我正在尝试创建一些带有文本的图像。这是我创建的功能:
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);