折雨的天空
PHP的GD库生成发光文字
2024-6-12 我好笨


用到一个开源库:



https://imagettftextblur.agjgd.org/examples/shadow/







github地址:https://github.com/andrewgjohnson/imagettftextblur







使用示例:







//引入文字发光
include __ROOTDIR__."libs/imagettftextblur/imagettftextblur.php";

// 背景颜色
$text_color = imagecolorallocate($im, 216, 227, 231);
$shadow_color = imagecolorallocate($im, 57, 47, 65);

//定义x轴在字体上增加的大小
$xleft=6;
foreach ($str as $k=>$v){

if ($type=='1'){
//imagettftext($im, $size, 0, ($width-mb_strlen($v)*($size+$xleft))/2, ($height-$k*($size+56))/2+(count($str)*10), $text_color, $font, $v);
$x_offset=($width-mb_strlen($v)*($size+$xleft))/2;
$y_offset=($height-$k*($size+56))/2+(count($str)*10);
}else{
//imagettftext($im, $size, 0, ($width-mb_strlen($v)*($size+$xleft))/2, ($height-$k*($size+36))/2+(count($str)*12), $text_color, $font, $v);
$x_offset=($width-mb_strlen($v)*($size+$xleft))/2;
$y_offset=($height-$k*($size+36))/2+(count($str)*12);
}
// place the shadow onto our image
imagettftextblur($im, $size, 0, $x_offset + 5, $y_offset + 5, $shadow_color, $font,$v, 10);
// place the text onto our image
imagettftextblur($im, $size, 0, $x_offset, $y_offset, $text_color, $font, $v);
}



生成示例:



20240612-11.png

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容