用到一个开源库:
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);
}