note 112467 added to function.imagettftext
| From: | lilfo | Date: | Wed, 19 Jun 2013 16:43:02 +0000 |
| Subject: | note 112467 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195286@lists.php.net to get a copy of this message | ||
If you need to rotate text around center you can use this function instead of imagettftext_cr() by
pillepop2003 that doesn't mantain the same center of the original image (shifting a bit):
function imagettftext_center_rotate(&$im, $size, $angle, $x, $y, $color, $fontfile, $text)
{
// retrieve boundingbox of the non rotated text
$bbox = imagettfbbox($size, 0, $fontfile, $text);
//calculate the parameters of the line from lowerleft to upperright point
$m1 = ($bbox[5]-$bbox[1])/($bbox[4]-$bbox[0]);
$q1 = $bbox[1]-($bbox[0]*$m1);
//calculate the parameters of the line from upperleft to lowerright point
$m2 = ($bbox[3]-$bbox[7])/($bbox[2]-$bbox[6]);
$q2 = $bbox[7]-($bbox[6]*$m2);
//calculate the rectangle center (intersection of the two lines)
$vx = ($q1-$q2)/($m2-$m1);
$vy = ($m1*($q1-$q2)/($m2-$m1))+$q1;
// retrieve boundingbox of the rotated text
$bbox = imagettfbbox($size, $angle, $fontfile, $text);
//calculate the parameters of the line from lowerleft to upperright point
$m1 = ($bbox[5]-$bbox[1])/($bbox[4]-$bbox[0]);
$q1 = $bbox[1]-($bbox[0]*$m1);
//calculate the parameters of the line from upperleft to lowerright point
$m2 = ($bbox[3]-$bbox[7])/($bbox[2]-$bbox[6]);
$q2 = $bbox[7]-($bbox[6]*$m2);
//calculate the rectangle center (intersection of the two lines)
$nx = ($q1-$q2)/($m2-$m1);
$ny = ($m1*($q1-$q2)/($m2-$m1))+$q1;
//calculate the x and y shifting needed
$dx = $nx - $vx;
$dy = $ny - $vy;
// new pivotpoint
$px = $x-$dx;
$py = $y-$dy;
//output
return imagettftext($im, $size, $angle, $px, $py, $color, $fontfile, $text);
}
----
Server IP: 69.147.83.199
Probable Submitter: 78.12.57.214
----
Manual Page -- http://php.net/manual/en/function.imagettftext.php
Edit -- https://master.php.net/note/edit/112467
Del: integrated -- https://master.php.net/note/delete/112467/integrated
Del: useless -- https://master.php.net/note/delete/112467/useless
Del: bad code -- https://master.php.net/note/delete/112467/bad+code
Del: spam -- https://master.php.net/note/delete/112467/spam
Del: non-english -- https://master.php.net/note/delete/112467/non-english
Del: in docs -- https://master.php.net/note/delete/112467/in+docs
Del: other reasons-- https://master.php.net/note/delete/112467
Reject -- https://master.php.net/note/reject/112467
Search -- https://master.php.net/manage/user-notes.php