You are here: Re: [PHP] weird results from imagettfbbox() « PHP « IT news, forums, messages
Re: [PHP] weird results from imagettfbbox()

Posted by Philip Hallstrom on 10/12/31 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?

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
>

 

Navigation:

[Reply to this 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

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