Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training,
learning paths, books, tutorials, and more.

Chapter 15. Graphics

Introduction

With
the assistance of the GD library, you can use PHP to create
applications that use dynamic images to display stock quotes, reveal
poll results, monitor system performance, and even create games.
However it’s not like using Photoshop or GIMP; you
can’t draw a line by moving your mouse. Instead, you
need to precisely specify a shape’s type, size, and
position.

GD has an existing API, and PHP tries to follows its syntax and
function-naming conventions. So, if you’re familiar
with GD from other languages, such as C or Perl, you can easily use
GD with PHP. If GD is new to you, it may take a few minutes to figure
it out, but soon you’ll be drawing like Picasso.

The feature set of GD
varies greatly depending on which version GD you’re
running and which features were enabled during configuration.
Versions of GD up to 1.6 supported reading and writing
GIFs, but this code was removed due to patent
problems. Instead, newer versions of GD support
JPEGs, PNGs, and
WBMPs. Because PNGs are generally smaller than GIFs, allow you to use
many more colors, have built-in gamma correction, and are supported
by all major web browsers, the lack of GIF support is classified as a
feature, not a bug. For more on PNG, go to
http://www.libpng.org/pub/png/ or read Chapter 21, “PNG
Format,” of Web Design in a
Nutshell written by Jennifer Niederst
(O’Reilly).