使带文本的图像功能不起作用


Make Image with Text Function Not Working

我正在尝试创建一些带有文本的图像。这是我创建的功能:

function makeTitleImage($text){
  $im = imagecreatetruecolor(160,160);
  $background_color = imagecolorallocate($im,154,205,50);
  $text_color = imagecolorallocate($im,255,255,255);
  imagefill($im,0,0,$background_color);
  imagettftext($im,10,0,0,$text_color,"./ASansBlack.ttf",$text);
  header('Content-Type: image/png');
  imagepng($im,($text.'.jpg'));
  imagedestroy($im);
}

这创建了一个160x160px的图像,背景色但没有文本,命名恰当(所以我知道$text被正确传入)。.ttf文件的路径是准确的。不确定还会发生什么?可能是一些愚蠢的事情。

谢谢!

imagettftext函数缺少一个参数,该参数是文本的y坐标。试试之类的东西

imagettftext($im,10,0,0,10,$text_color,"./ASansBlack.ttf",$text);