note 27677 added to function.imagettftext
| From: | andrew at rack1 dot php dot net | Date: | Sun, 15 Dec 2002 10:23:41 +0000 |
| Subject: | note 27677 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40926@lists.php.net to get a copy of this message | ||
Sorry ... I copy and pasted from an old copy of the code. These two functions need to be replaced
for the TTF wrapping and alignment routines to work properly:
function ImageTtfTextAlign(&$image, $font_size, $angle_degrees, $x, $y, $colour, $font, $text,
$length, $align)
{
$align = strtoupper($align);
if (strcmp($align, "LEFT"))
{
$angle_radians = $angle_degrees * pi() / 180;
$bbox = imagettfbbox($font_size, $angle_degrees, $font, $text);
$text_length = ImageTextLength($bbox);
if (!strcmp($align, "CENTRE"))
$adjustment = ($length - $text_length) / 2;
elseif (!strcmp($align, "RIGHT"))
$adjustment = $length - $text_length;
else
$adjustment = 0;
$x += (int)round($adjustment * cos($angle_radians));
$y -= (int)round($adjustment * sin($angle_radians));
}
imagettftext($image, $font_size, $angle_degrees, $x, $y, $colour, $font, $text);
}
function ImageAddBbox($bbox1, $bbox2, $angle_degrees)
{
$angle_radians = $angle_degrees * pi() / 180;
$new_length = max(ImageTextLength($bbox1), ImageTextLength($bbox2));
$new_height = ImageTextHeight($bbox1) + ImageTextHeight($bbox2);
$bbox[0] = 0;
$bbox[1] = 0;
$bbox[2] = (int)ceil($new_length * cos($angle_radians));
$bbox[3] = (int)ceil($new_length * sin($angle_radians));
// add 5 pixels to space lines out
$bbox[6] = (int)ceil(0 - ($new_height + 5) * sin($angle_radians));
$bbox[7] = (int)ceil(0 - ($new_height + 5) * cos($angle_radians));
$bbox[4] = $bbox[2] + $bbox[6];
$bbox[5] = $bbox[3] + $bbox[7];
return $bbox;
}
--
http://www.php.net/manual/en/function.imagettftext.php
http://master.php.net/manage/user-notes.php?action=edit+27677
http://master.php.net/manage/user-notes.php?action=delete+27677
http://master.php.net/manage/user-notes.php?action=reject+27677