note 75491 added to function.imagettfbbox
| From: | NateSweet at osu1 dot php dot net | Date: | Fri, 01 Jun 2007 19:11:21 +0000 |
| Subject: | note 75491 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127108@lists.php.net to get a copy of this message | ||
An improvement to the convertBoundingBox function. The previous function was completely wrong. My
confusion came from characters like "1" and "_" that are rendered to the right
or below the basepoint (in the font I'm using). I ended up using mike at mikeleigh dot
com's function with a fix for these characters, and a "belowBasepoint" value.
<?php
function convertBoundingBox ($bbox) {
if ($bbox[0] >= -1)
$xOffset = -abs($bbox[0] + 1);
else
$xOffset = abs($bbox[0] + 2);
$width = abs($bbox[2] - $bbox[0]);
if ($bbox[0] < -1) $width = abs($bbox[2]) + abs($bbox[0]) - 1;
$yOffset = abs($bbox[5] + 1);
if ($bbox[5] >= -1) $yOffset = -$yOffset; // Fixed characters below the baseline.
$height = abs($bbox[7]) - abs($bbox[1]);
if ($bbox[3] > 0) $height = abs($bbox[7] - $bbox[1]) - 1;
return array(
'width' => $width,
'height' => $height,
'xOffset' => $xOffset, // Using xCoord + xOffset with imagettftext puts the left most
pixel of the text at xCoord.
'yOffset' => $yOffset, // Using yCoord + yOffset with imagettftext puts the top most
pixel of the text at yCoord.
'belowBasepoint' => max(0, $bbox[1])
);
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 67.161.110.125
----
Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php
Edit -- https://master.php.net/note/edit/75491
Del: integrated -- https://master.php.net/note/delete/75491/integrated
Del: useless -- https://master.php.net/note/delete/75491/useless
Del: bad code -- https://master.php.net/note/delete/75491/bad+code
Del: spam -- https://master.php.net/note/delete/75491/spam
Del: non-english -- https://master.php.net/note/delete/75491/non-english
Del: in docs -- https://master.php.net/note/delete/75491/in+docs
Del: other reasons-- https://master.php.net/note/delete/75491
Reject -- https://master.php.net/note/reject/75491
Search -- https://master.php.net/manage/user-notes.php