Outlining
Outlining text is also fairly simple to do. If you think about it, an outline is just drawing the text left and right, above and below the main text, then drawing the main text over it. This theoretically works with every font because it moves one pixel at a time. To create an outline, you need only know the width of the outline, then write a for loop:
<?php
function imagettftextoutline(&$im,$size,$angle,$x,$y,&$col,
&$outlinecol,$fontfile,$text,$width) {
// For every X pixel to the left and the right
for ($xc=$x-abs($width);$xc<=$x+abs($width);$xc++) {
// For every Y pixel to the top and the bottom
for ($yc=$y-abs($width);$yc<=$y+abs($width);$yc++) {
// Draw the text in the outline color
$text1 = imagettftext($im,$size,$angle,$xc,$yc,$outlinecol,$fontfile,$text);
}
}
// Draw the main text
$text2 = imagettftext($im,$size,$angle,$x,$y,$col,$fontfile,$text);
}
?>
By calling
imagettftextoutline($img,40,0,10,50,$red,$black,"arial.ttf","AaBbCcDd",3)
, we get an image like this: