note 86854 modified in function.imagettfbbox by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Nov 2008 19:27:38 +0000 |
| Subject: | note 86854 modified in function.imagettfbbox by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146247@lists.php.net to get a copy of this message | ||
SIMPLE OVERLOADED FUNCTION: Adds TTF Center and Right Alignment to co ordintate points.
Correctly demonstrates the use of the bouning box TTF function and the array of coordinates that it
returns.
After obtaining values and adjusting based on a set of values [L, C, R], it uses simple math based
of the length of the text to move it from the origin (x = 0 )
<?php
function imagettftextalign($image, $size, $angle, $x, $y, $color, $font, $text,
$alignment='L')
{
//check width of the text
$bbox = imagettfbbox ($size, $angle, $font, $text);
$textWidth = $bbox[2] - $bbox[0];
switch ($alignment) {
case "R":
$x -= $textWidth;
break;
case "C":
$x -= $textWidth / 2;
break;
}
//write text
imagettftext ($image, $size, $angle, $x, $y, $color, $font, $text);
}
?>
--was--
SIMPLE OVERLOADED FUNCTION: Adds TTF Center and Right Alignment to co ordintate points.
Correctly demonstrates the use of the bouning box TTF function and the array of coordinates that it
returns.
After obtaining values and adjusting based on a set of values [L, C, R], it uses simple math based
of the length of the text to move it from the origin (x = 0 )
function imagettftextalign($image, $size, $angle, $x, $y, $color, $font, $text,
$alignment='L')
{
//check width of the text
$bbox = imagettfbbox ($size, $angle, $font, $text);
$textWidth = $bbox[2] - $bbox[0];
switch ($alignment) {
case "R":
$x -= $textWidth;
break;
case "C":
$x -= $textWidth / 2;
break;
}
//write text
imagettftext ($image, $size, $angle, $x, $y, $color, $font, $text);
}
http://php.net/manual/en/function.imagettfbbox.php