Reply to weird results from imagettfbbox()

Your name:

Reply:


Posted by "Aaron Todd" on 10/04/28 11:25

I have an array of strings in which I am passing to imagettfbbox() in order
to calculate the height of the text box for each string. I am then
subtracting the height from the y position in order to deviate the pivot
point form the top left corner to the bottom left corner when I used
imagettftext() to draw the text on an image. I am giving both commands a
fontsize of 50, an angle of 0 and I am using the font ARIAL.

I am having an issue where the first string comes back with a height of 50
and the next comes back with 47. Then 50 again for the next following
string and then 47 again for the next one foloowing that. It keeps going on
and on like this and I do not understand why. I am using the same font,
font size, and angle for each string so shouldnt they all come back as the
same size?

Here's a snippet of what I am doing:

$file = "this can be any file";
$im = imagecreatefromjpeg($file);

$textcolor = imagecolorallocate($im, 0, 0, 0);
$fontfile = "arial.ttf";
$fontsize = 50;

$arr = split("CR", $_GET['text']);

$boxes = count($arr);
if (preg_match('/[0-9]/', $boxes)){
for($c=0;$c<$boxes;$c++){
$text = stripslashes($arr[$c]);
$y = $fontsize * $c;
$bbox = imagettfbbox($fontsize, 0, $fontfile, $text);
$dy = $bbox[7] - $bbox[1];
$py = $y-$dy;

imagettftext($im, $fontsize, 0, 1, $py, $textcolor, $fontfile, $text);
}
}

header("Content-type: image/jpeg");
imagejpeg($im, "" ,95);
imagedestroy($im);

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация