Specifications
It takes as parameters the image identifier, the font, the x and y coordinates to start writing the
text, the text to write, and the color.
The font is a number between 1 and 5. These represent a set of built-in fonts. As an alternative
to these, you can use TrueType fonts, or PostScript Type 1 fonts. Each of these font sets has a
corresponding function set. We will use the TrueType functions in the next example.
A good reason for using one of the alternative font function sets is that the text written by
ImageString() and associated functions, such as ImageChar() (write a character to the image)
is aliased. The TrueType and PostScript functions produce anti-aliased text.
If you’re not sure what the difference is, look at Figure 19.2. Where curves or angled lines
appear in the letters, the aliased text appears jagged. The curve or angle is achieved by using a
“staircase” effect. In the anti-aliased image, when there are curves or angles in the text, pixels
in colors between the background and the text color are used to smooth the text’s appearance.
Advanced PHP Techniques
P
ART IV
408
FIGURE 19.2
Normal text appears jagged, especially in a large font size. Anti-aliasing smooths the curves and corners of the letters.
Outputting the Final Graphic
You can output an image either directly to the browser, or to a file.
In this example, we’ve output the image to the browser. This is a two-stage process. First, we
need to tell the Web browser that we are outputting an image rather than text or HTML. We do
this by using the
Header() function to specify the MIME type of the image:
Header (“Content-type: image/png”);
Normally when you retrieve a file in your browser, the MIME type is the first thing the Web
server sends. For an HTML or PHP page (post execution), the first thing sent will be
Content-type: text/html
24 7842 CH19 3/6/01 3:42 PM Page 408










