note 51373 added to function.imagettfbbox
| From: | ryan at retronetworks dot com | Date: | Tue, 29 Mar 2005 03:46:40 +0000 |
| Subject: | note 51373 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87125@lists.php.net to get a copy of this message | ||
Here is a function that lets you write a string with your own "font tracking" level (the
amount of pixels separating each character). It uses imagettfbbox to determine the width of each
character, so it doesn't discriminate against the skinnier of characters. For this example,
let $t = the amount of distance in pixels you want to separate each character from its neighbors.
<?php
function ImageTTFTextWithTracking($im, $size, $angle, $t, $x, $y, $color, $font, $text) {
$numchar = strlen($text);
for($i = 0; $i < $numchar; $i++) {
# Assign character
$char[$i] = substr($text, $i, 1);
# Write character
imagettftext($im, $size, $angle, ($x + $w + ($i * $t)), $y, $color, $font, $char[$i]);
# Get width of character
$width = imagettfbbox($size, $angle, $font, $char[$i]);
$w = $w + $width[2];
}
}
?>
Be aware that it currently does not work for angles other than the 0 default (I have no need for
that).
----
Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51373
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51373&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51373&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51373&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51373&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51373&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51373&report=yes
Search -- http://master.php.net/manage/user-notes.php