PDA

Click to See Complete Forum and Search --> : [RESOLVED] Question about imagecreate


Kal-El
Jul 18th, 2007, 09:52 AM
This is my code:

$text_array = array("Joel", "Almeida", "García", "Joel Almeida García");
$text = $text_array[rand(0, count($text_array)-1)];

$im = imagecreate(50, 22);
$bgColor = imagecolorallocate($im, 255, 255, 255);
$fgColor = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($im, $bgColor);
imagestring($im, 2, 0, 0, $text, $fgColor);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);

The above code, creates a png image from a random text....my question is: How can I calculate, by code, the corrrect values width and height of imagecreate, based on the returned text?

Thanks

penagate
Jul 18th, 2007, 09:57 AM
You can use imagefontwidth() and imagefontheight() to get the dimensions of a character in a particular font, and then multiply those figures by the length of your text.

Kal-El
Jul 18th, 2007, 01:49 PM
Cool! Thanks for the tip :)