note 36357 added to function.imagettftext
| From: | jvkootenNotThisPart at planet dot nl | Date: | Tue, 07 Oct 2003 03:42:46 +0000 |
| Subject: | note 36357 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57954@lists.php.net to get a copy of this message | ||
I noticed that the specified y coordinate in this function at least for some fonts (but maybe all)
means the font's baseline, and not the true font's bottom line. This means that when
creating an image that is exactly the size of the text you want to render (calculated using the
imagettfbbox function), letters like j, p, g, etc. fall off the image area and there's some
space at the top. I found this solution.
$box = imagettfbbox($size, 0, $fontfile, $txt . "Mg_|");
$height = ($box[1] - $box[7]);
$box = imagettfbbox($size, 0, $fontfile, $txt);
$width = ($box[2] - $box[0]);
$box1 = imagettfbbox($size, 0, $fontfile, "o");
$box2 = imagettfbbox($size, 0, $fontfile, "g");
$baseline = ($box2[1] - $box2[7]) - ($box1[1] - $box1[7]);
$im = imagecreate($width, $height);
imagettftext ($img, $size, 0, 0, $height - $baseline, $rgbfore, $fontfile, $txt);
----
Manual Page -- http://www.php.net/manual/en/function.imagettftext.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36357
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36357&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36357&report=yes
Search -- http://master.php.net/manage/user-notes.php