note 48938 added to function.imagettftext
| From: | pillepop2003 at rc1 dot vip dot ukl dot yahoo dot com | Date: | Wed, 12 Jan 2005 13:14:24 +0000 |
| Subject: | note 48938 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83142@lists.php.net to get a copy of this message | ||
Hey guys,
check this function if you want to rotate the text around its center and not its "lower
left" pivot-point:
<?php
// Put center-rotated ttf-text into image
// Same signature as imagettftext();
function imagettftext_cr(&$im, $size, $angle, $x, $y, $color, $fontfile, $text)
{
// retrieve boundingbox
$bbox = imagettfbbox($size, $angle, $fontfile, $text);
// calculate deviation
$dx = ($bbox[2]-$bbox[0])/2.0 - ($bbox[2]-$bbox[4])/2.0; // deviation left-right
$dy = ($bbox[3]-$bbox[1])/2.0 + ($bbox[7]-$bbox[1])/2.0; // deviation top-bottom
// new pivotpoint
$px = $x-$dx;
$py = $y-$dy;
return imagettftext($im, $size, $angle, $px, $py, $color, $fontfile, $text);
}
?>
Big up
Phil
----
Manual Page -- http://www.php.net/manual/en/function.imagettftext.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48938
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48938&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48938&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48938&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48938&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48938&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48938&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48938&report=yes
Search -- http://master.php.net/manage/user-notes.php