note 53736 added to function.imagettfbbox
| From: | info at rainer-schuetze dot de | Date: | Sat, 11 Jun 2005 04:32:41 +0000 |
| Subject: | note 53736 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90249@lists.php.net to get a copy of this message | ||
according function by jtopland at hive dot no
08-Feb-2004 03:26
soukhinov at mail dot ru was right, the function doesn't work with 180°. By the way it was a
intresting way to trasform the angle to radian. Change the calculation of the angle to the
following: $angle = $angle/ 180 * pi();
The function to calc. the points is correct. Sorry to say this, but the cal. of the height and width
is incorrect. I used the version from LB (11-Feb-2004 08:55)
/**
* return width and height, offset [left, top] of a ttf character
* @param string $font : the font file
* @param string $text : the character
* @param int $size : the font size
* @param int $angle : the angle
* @access private
* @return array of the width and height, left and top.
**/
function _getCharacterSize($font, $text, $size, $angle)
{
// Get the boundingbox from imagettfbbox(), which is correct when angle is 0
$bbox = imagettfbbox($size, 0, $font, $text);
// Rotate the boundingbox
$angle = $angle/ 180 * pi();
for ($i=0; $i<4; $i++)
{
$x = $bbox[$i * 2];
$y = $bbox[$i * 2 + 1];
$bbox[$i * 2] = cos($angle) * $x - sin($angle) * $y; // X
$bbox[$i * 2 + 1] = sin($angle) * $x + cos($angle) * $y; // Y
}
// Variables which tells the correct width and height
$bbox["left"] = 0- min($bbox[0],$bbox[2],$bbox[4],$bbox[6]);
$bbox["top"] = 0- min($bbox[1],$bbox[3],$bbox[5],$bbox[7]);
$bbox["width"] = max($bbox[0],$bbox[2],$bbox[4],$bbox[6]) -
min($bbox[0],$bbox[2],$bbox[4],$bbox[6]);
$bbox["height"] = max($bbox[1],$bbox[3],$bbox[5],$bbox[7]) -
min($bbox[1],$bbox[3],$bbox[5],$bbox[7]);
return $bbox;
}
----
Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53736
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53736&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53736&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53736&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53736&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53736&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53736&report=yes
Search -- http://master.php.net/manage/user-notes.php