我在 PHP/GD 中将文本写入图像模板得到了很好的结果,文本换行很好但不是“平滑”,这是我正在使用的代码:
<?php
header("Content-type: image/png");
$text = "go to school go to school go to school go to school go to school go to school go to school go to school go to school go to school go to school ";
$arrText=explode("\n",wordwrap($text,60,"\n"));
$im = imagecreatefrompng("template.png");
$y = 15; //vertical position of text
foreach($arrText as $arr)
{
$white = imagecolorallocate($im,0,0,0); //sets text color
imagestring($im,5,15,$y,trim($arr),$white); //create the text string for image,added trim() to remove unwanted chars
$y = $y+20;
}
imagepng($im);
imagedestroy($im);
?>