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:

outlining” makes use of the built-in PHP functions abs( ) and imagettftext( ).

01 <?php
02 
03 function imagettftextoutline(&$im,$size,$angle,$x,$y,&$col,&$outlinecol,$fontfile,$text,$width)
04 {
05     // For every X pixel to the left and the right
06     for($xc = $x-abs($width); $xc <= $x+abs($width); $xc++)
07     {
08         // For every Y pixel to the top and the bottom
09          for($yc = $y-abs($width); $yc <= $y+abs($width); $yc++)
10         {
11             // Draw the text in the outline color
12             $text1 = imagettftext($im,$size,$angle,$xc,$yc,$outlinecol,$fontfile,$text);
13         }
14     }
15     // Draw the main text
16     $text2 = imagettftext($im,$size,$angle,$x,$y,$col,$fontfile,$text);
17 }
18  
19 ?>