I'm trying to create some images with text on them. Here is the function I have created:
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);
}
This creates a 160x160px image with the background colour but no text, named appropriately (so I know $text
is being passed in correctly). The path to the .ttf
file is accurate. Not sure what else could be going on? Probably something silly.
Thanks!
Your imagettftext
function is missing a parameter, which is the y-coordinate of the text. Try something like
imagettftext($im,10,0,0,10,$text_color,"./ASansBlack.ttf",$text);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.