note 75333 added to function.imagettfbbox
| From: | lassialdotgmaildotcom at osu1 dot php dot net | Date: | Thu, 24 May 2007 11:46:16 +0000 |
| Subject: | note 75333 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126866@lists.php.net to get a copy of this message | ||
Ralph Bolton commented about the difference in calculating the bounding box size vs. aligning text
base line.
The workaround for this issue is to calculate the difference in height between a character going
below baseline and one above the baseline. This is likely going to vary from font to font, so
I'd suggest something like this:
<?php
function fontBaselineOffset($font, $fontSize)
{
//this should be above baseline
$test2="H";
//some of these additional letters should go below it
$test3="Hjgqp";
//get the dimension for these two:
$box2 = imageTTFBbox($fontSize,0,$font,$test2);
$box3 = imageTTFBbox($fontSize,0,$font,$test3);
//return the offset value
return abs((abs($box2[5]) + abs($box2[1])) - (abs($box3[5]) + abs($box3[1])));
}
?>
This is not perfect yet. You should define a range of allowed characters that can go below baseline,
compare them to the ones actually found in your string and use them instead of the string $test3
used in the example function above. This should avoid problems with letters that go further below
baseline than the others (e.g. there could be a difference between 'g' and 'p')
----
Server IP: 62.237.7.3
Probable Submitter: 128.214.215.13
----
Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php
Edit -- https://master.php.net/note/edit/75333
Del: integrated -- https://master.php.net/note/delete/75333/integrated
Del: useless -- https://master.php.net/note/delete/75333/useless
Del: bad code -- https://master.php.net/note/delete/75333/bad+code
Del: spam -- https://master.php.net/note/delete/75333/spam
Del: non-english -- https://master.php.net/note/delete/75333/non-english
Del: in docs -- https://master.php.net/note/delete/75333/in+docs
Del: other reasons-- https://master.php.net/note/delete/75333
Reject -- https://master.php.net/note/reject/75333
Search -- https://master.php.net/manage/user-notes.php