提问人: 提问时间:7/31/2015 更新时间:7/31/2015 访问量:183
GD 阴影到黑色或透明背景
GD Shadow to Black or Transparent Background
问:
我正在使用 Andrew G. Johnson 的 imagettftextblur(),它很棒,但是如何添加从文本颜色到黑色背景的阴影,或者动态地添加到透明图像上的任何背景颜色?如果我将阴影设置为黑色,它就会消失,而将其设置为较浅的颜色看起来像一个斑点。在白色背景上,它看起来很棒,但在黑色或其他深色背景下却不然。
我使用的代码如下,并调用了几个自定义函数,包括 imagettftextblur(),但其他函数与问题无关。我试图发布示例图像,但无法。
函数 textimage($Strings,$Fonts,$FontSize,$Angle,$EnableShadow,$CenterAlign) {
$FontPath = $_SERVER['DOCUMENT_ROOT'] . "/functions/truetype/";
if (is_array($Strings) === TRUE && is_array($Fonts) === TRUE) :
foreach (array_combine($Strings, $Fonts) AS $Strings => $Fonts) :
$Fonts = $FontPath.$Fonts.".ttf";
$TextDimensions = imagettfbbox($FontSize,$Angle,$Fonts,$Strings);
$Width = abs($TextDimensions[4] - $TextDimensions[0] + 5);
$Height = abs($TextDimensions[5] - $TextDimensions[1]) + 10;
$Image = imageCreateTransparent($Width,$Height);
$TextColor = imagecolorallocate($Image,255,204,153);
$ShadowColor = imagecolorallocate($Image,119,119,119);
$y_offset = abs($TextDimensions[5]);
if ($EnableShadow === TRUE):
if ($CenterAlign === TRUE):
$x_offset = CenterText($FontSize,$Fonts,$Strings,$Width);
else:
$x_offset = ($Width / 2) - ((min($TextDimensions[2],$TextDimensions[4]) - max($TextDimensions[0],$TextDimensions[6])) / 2);
endif;
imagettftextblur($Image,$FontSize,$Angle,$x_offset+5,$y_offset+5,$ShadowColor,$Fonts,$Strings,10);
imagettftextblur($Image,$FontSize,$Angle,$x_offset,$y_offset,$TextColor,$Fonts,$Strings);
else:
if ($CenterAlign === TRUE):
$x_offset = CenterText($FontSize,$Fonts,$Strings,$Width);
else:
$x_offset = ($Width / 2) - ((min($TextDimensions[2],$TextDimensions[4]) - max($TextDimensions[0],$TextDimensions[6])) / 2);
endif;
imagettftext($Image,$FontSize,$Angle,$x_offset,$y_offset,$TextColor,$Fonts,$Strings);
endif;
endforeach;
endif;
return imagepng($Image);
imagedestroy($Image);
}
我使用单独的脚本调用它:
header('内容类型:image/png');
require(“logo_functions.php”);
$Strings = array("Packard ","/ IMPERIAL page");
$Fonts = array("racew17","timesbd");
$Size = 20;
$Angle = 0;
$Shadow = TRUE;
$CenterAlign = TRUE;
echo textimage($Strings,$Fonts,$Size,$Angle,$Shadow,$CenterAlign);
答: 暂无答案
评论