Voting

: one plus zero?
(Example: nine)

The Note You're Voting On

ryan at retronetworks dot com
20 years ago
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).

<< Back to user notes page

To Top