note 51494 deleted from function.imagettftext by cmb
| From: | cmb@php.net | Date: | Sun, 28 Jul 2019 08:13:19 +0000 |
| Subject: | note 51494 deleted from function.imagettftext by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211729@lists.php.net to get a copy of this message | ||
Note Submitter: nick
----
A trivial function to get right or centre aligned horizontal text:
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);
}