05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 9-4. Adding text to an image<br />

<br />

Figure 9-2 shows the output of Example 9-4.<br />

Figure 9-2. The image with text<br />

The ImageString( ) function adds text to an image. Specify the top-left point of the<br />

text, as well as the color and the font to use:<br />

Fonts<br />

ImageString(image, font, x, y, text, color);<br />

Fonts in GD are identified by numbers. The five built-in fonts are shown in Figure 9-3.<br />

Figure 9-3. Native GD fonts<br />

You can create your own fonts and load them into GD using the ImageLoadFont( )<br />

function. However, these fonts are binary and architecture-dependent. Using True-<br />

Type fonts with the TrueType functions in GD provides much more flexibility.<br />

TrueType Fonts<br />

To use TrueType fonts with GD, <strong>PHP</strong> must have been compiled with TrueType support<br />

via the FreeType library. Check your phpinfo( ) page (as described earlier in this<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

Images with Text | 221

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!