TTF Fonts

This tutorial will cover some aspects of using fonts with GD. The basic code is as follows:
imagettftext($image,$pointsize,$rotation,$x,$y,$color,$font,$text);

This first example shows a basic use with 3 colors. The gray color is 1 pixel to the left and to the top of the white color, while black is 1 pixel to the right and 1 pixel down from the white color. These letters overwrite each other, so white is drawn last. If you look at the code, you will see a minus sign in front of the white color. This is used to antialias that color.

The second image is the same script as the first, with the colors changed around. Gray background and font, top outline black, bottom outline white.

Right click, select all, ctrl+c to copy.
This uses imagecopymerge (future lesson) with an plasma image on top and truecolor transparent image in back, alpha color.


Right click, select all, ctrl+c to copy.
Another version with plasma in background and transparent truecolor image on top.
Right click, select all, ctrl+c to copy.

This example uses imagettfbbox along with imagettftext. I do not fully understand it, but it supposedly allows you to create a logo without having to figure out the size of the background. I got this script on line.
Right click, select all, ctrl+c to copy.
Rotation loop:
Sally figured this one out.
Right click, select all, ctrl+c to copy.
Font with x,y and color in a loop
Right click, select all, ctrl+c to copy.
This is a script found on line that draws a stroke color around the font. You can build it up by adding smaller and smaller strokewidths, while keeping all font calls at the same x,y location. You need to add 2 colors to this function, alternating the stroke and text colors with each call. (You can call it only once for a single outline around a font.)
Click image for full size.
This is a script I found on line that writes something in a circle. Instead of words, I used a dingbat. The bottom lines of this script also introduces the imagefilltoborder() function, which basically fills the background in a color until it gets to another color. You specify the colors. It is easier to understand by seeing it. Just download the zip and comment out the imaging lines on the bottom and then uncomment them to view what happens. >>Circle Zip<<
Click image to see color change.
Random Color font. Use <embed src='...php'> if you want it to blink on a page.
Right click, select all, ctrl+c to copy.
This is a script I found on line years ago. It takes an image and gets a color from a pixel in the image. Uses imagecopymerge.
Translucent Text
Dingbat viewerThis dingbat viewer takes a short URL to show the font.
Dingbat viewer zip
This is a script to show all the ttf fonts in your directory. You need to change the name of the directory if it is not fonts.
Directory fonts zip
Lesson 8 - Part 2