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.

FreeType Support enabled<br />

FreeType Linkage with freetype<br />

JPG Support enabled<br />

PNG Support enabled<br />

WBMP Support enabled<br />

Pay close attention to the image types listed. These are the types of images you will<br />

be able to generate.<br />

There have been three major revisions of GD and its API. Versions of GD before 1.6<br />

support only the GIF format. Version 1.6 and later support JPEG, PNG, and WBMP,<br />

but not GIF (the GIF file format uses patented algorithms that require royalties). Version<br />

2.x of GD added several new drawing primitives.<br />

All GD 1.x versions are limited to 8-bit color. That is, the images you generate or<br />

manipulate with GD 1.x can contain only 256 different colors. For simple charts or<br />

graphs this is more than sufficient, but if you are dealing with photos or other images<br />

with more than 256 colors you will find the results less than satisfactory. Upgrade to<br />

GD 2.x to get true-color support, or use the Imlib2 library and corresponding <strong>PHP</strong><br />

extension instead. The API for the Imlib2 extension is somewhat different from the<br />

GD extension API and is not covered in this chapter.<br />

Basic Graphics Concepts<br />

An image is a rectangle of pixels that have various colors. Colors are identified by<br />

their position in the palette, an array of colors. Each entry in the palette has three<br />

separate color values—one for red, one for green, and one for blue. Each value<br />

ranges from 0 (this color not present) to 255 (this color at full intensity).<br />

Image files are rarely a straightforward dump of the pixels and the palette. Instead,<br />

various file formats (GIF, JPEG, PNG, etc.) have been created that attempt to compress<br />

the data somewhat to make smaller files.<br />

Different file formats handle image transparency, which controls whether and how<br />

the background shows through the image, in different ways. Some support an alpha<br />

channel, an extra value for every pixel reflecting the transparency at that point. Others<br />

simply designate one entry in the palette as indicating transparency.<br />

Antialiasing is where pixels at the edge of a shape are moved or recolored to make a<br />

gradual transition between the shape and its background. This prevents the rough<br />

and jagged edges that can make for unappealing images. Some functions that draw<br />

on an image implement antialiasing.<br />

With 256 possible values for each of red, green, and blue, there are 16,777,216 possible<br />

colors for every pixel. Some file formats limit the number of colors you can have<br />

in a palette (e.g., GIF supports no more than 256 colors); others let you have as<br />

216 | Chapter 9: Graphics<br />

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

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!