note 68518 added to function.imagettfbbox
| From: | marclaz at osu1 dot php dot net | Date: | Mon, 31 Jul 2006 13:13:00 +0000 |
| Subject: | note 68518 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115372@lists.php.net to get a copy of this message | ||
Please note that as imageTTFBbox and imageTTFText functions return an array of coordinates which
could be negative numbers care must be taken with height and width calculations.
The rigth way to do that is to use the abs() function:
for an horizontal text:
$box = @imageTTFBbox($size,0,$font,$text);
$width = abs($box[4] - $box[0]);
$height = abs($box[5] - $box[1]);
Then to center your text at ($x,$y) position the code should be like that:
$x -= $width/2;
$y += $heigth/2;
imageTTFText($img,$size,0,$x,$y,$color,$font,$text);
this because (0,0) page origin is topleft page corner and (0,0) text origin is lower-left readable
text corner.
Hope this help.
----
Server IP: 195.221.21.36
Probable Submitter: 164.129.1.39 (proxied: unknown, unknown)
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php
Edit -- https://master.php.net/note/edit/68518
Del: integrated -- https://master.php.net/note/delete/68518/integrated
Del: useless -- https://master.php.net/note/delete/68518/useless
Del: bad code -- https://master.php.net/note/delete/68518/bad+code
Del: spam -- https://master.php.net/note/delete/68518/spam
Del: non-english -- https://master.php.net/note/delete/68518/non-english
Del: in docs -- https://master.php.net/note/delete/68518/in+docs
Del: other reasons-- https://master.php.net/note/delete/68518
Reject -- https://master.php.net/note/reject/68518
Search -- https://master.php.net/manage/user-notes.php