imagettfbox issue
Posted: Fri Aug 21, 2009 7:34 pm
I am using GD to create an image with text. Since the font, font size, and amount of text can vary, the idea was to use imagettfbox to determine the width and height of the text. Then use those values as the parameters for imagecreatetruecolor. However, for some reason, the $width and $height seems to be incorrect as the text is getting cut off.
Is there something I'm not understanding?
Thanks,
John
Code: Select all
//...
$bbox = imagettfbbox($size, 0, $font, $xml->channel->item->title[0]);
$width = abs($bbox[2]-$bbox[0]);
$height = abs($bbox[7]-$bbox[1]);
$im = imagecreatetruecolor($width, $height);
$bg = imagecolorallocatealpha($im, 255, 255, 255, 127);
$txt = imagecolorallocate($im, 0, 0, 0);
imagesavealpha($im, true);
imagefill($im, 0, 0 , $bg);
imagettftext($im, $size, 0, 10, 20, $txt, $font, $xml->channel->item->title[0]);
imagepng($im);
imagedestroy($im);Thanks,
John