Specifications
Advanced PHP Techniques
P
ART IV
402
One of the useful things you can do with PHP is create images on-the-fly. PHP has some built-
in image information functions, and you can also use the GD library to create new images or
manipulate existing ones. This chapter discusses how to use the image functions to achieve
some interesting and useful effects.
We will look at
• Setting up image support in PHP
• Understanding image formats
• Creating images
• Using text and fonts to create images
• Drawing figures and graphing data
Specifically, we’ll look at two examples: generating Web site buttons on-the-fly, and drawing a
bar chart using figures from a MySQL database.
Setting Up Image Support in PHP
Image support in PHP is available via the gd library, available from
http://www.boutell.com/gd/
Version 1.6.2 comes bundled with PHP 4. By default, the PNG format is supported. If you also
want to work with JPEGs, you will need to download jpeg-6b, and recompile gd with jpeg sup-
port included. You can download this from
ftp://ftp.uu.net/graphics/jpeg/
You will then need to reconfigure PHP with the
--with-jpeg-dir=/path/to/jpeg-6b
option, and recompile it.
If you want to use TrueType fonts in your images, you will also need the FreeType library.
This also comes with PHP 4. Alternatively, you can download this from
http://www.freetype.org/
If you want to use PostScript Type 1 fonts instead, you will need to download t1lib,
available from
ftp://ftp.neuroinformatik.ruhr-uni-bochum.de/pub/software/t1lib/
You will then need to run PHP’s configure program with
--with-t1lib[=path/to/t1lib]
24 7842 CH19 3/6/01 3:42 PM Page 402










