[PHP] weird results from imagettfbbox()

2005-08-31 Thread Aaron Todd
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); 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] weird results from imagettfbbox()

2005-08-31 Thread Philip Hallstrom

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?


Is each line of the file the same?  It's going to vary depending on what 
letters are in the string (ascenders and descenders for letters like 
qygpi, etc.).


maybe that's it?



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);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php