Page 547 - Beginning PHP 5.3
P. 547
Chapter 17: Generating Images with PHP
300 pixels
0,0 299,0
200 pixels
0,199 299,199
Figure 17-3
Image Types
Computers typically work with two types of images: raster and vector. Raster images (also known as
bitmap images) are made up of pixel data; in a 20 - pixel - wide by 20 - pixel - high color image there are 400
individual pixels making up the image, and each of these pixels has its own RGB color value. In contrast,
a vector image uses mathematical equations to describe the shapes that make up the image. The SVG
(Scalable Vector Graphics) format is a good example of a vector image. Vector images are great for
diagrams that include lines, curves, and blocks of color, but are not suitable for photographs or images
with lots of detail.
In this chapter you concentrate on working with raster images, which tend to be more common on the
Web. PHP ’ s GD image functions let you work with four main raster image formats — JPEG, PNG, and
GIF for desktop Web browsers, and WBMP images for mobile browsers. (You concentrate on desktop
Web images in this chapter.)
These four image formats are all compressed formats, which means that they use mathematical algorithms
to reduce the amount of storage required to describe the image. They play a key role in keeping your file
sizes small and download times short!
It ’ s important to know when to use each of these image formats. Although they are all raster images,
they use quite different compression techniques, and in certain situations one format works much better
than another.
The JPEG format uses lossy compression, in which some of the data in the original image is lost during
compression. The format is designed to work best with images like photographs, where there ’ s a lot of
subtle shading and few large blocks of a single color. It ’ s the format to use when a slight loss in quality
won ’ t be too apparent to the viewer.
Images in the PNG and GIF formats, on the other hand, are compressed in a lossless fashion, meaning
that no image data is lost during the compression process. Sharp edges and straight lines (which suffer
under JPEG compression) are reproduced faithfully. This technique works best with images that contain
lines and large blocks of color — cartoons and diagrams, for example.
509
9/21/09 2:48:36 PM
c17.indd 509
c17.indd 509 9/21/09 2:48:36 PM