note 36357 deleted from function.imagettftext by aidan
| From: | aidan@php.net | Date: | Mon, 20 Sep 2004 10:00:49 +0000 |
| Subject: | note 36357 deleted from function.imagettftext by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77026@lists.php.net to get a copy of this message | ||
Note Submitter: jvkootenNotThisPart at planet dot nl
----
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);