Page 546 - Beginning PHP 5.3
P. 546
Part III: Using PHP in Practice
Color Theory
Computers usually create colors using a color theory model called the RGB model . RGB stands for red,
green, and blue, the three basic colors that are combined to create the colors that you see on your
computer display. The RGB model is known as an additive color model because different amounts of red,
green, and blue are combined together to create the final color.
Each red, green, or blue component usually has a value between zero (no amount of that color) and 255
(the maximum amount). A pure blue color has an RGB value of 0,0,255 — the red and green values are
empty (zero) and the blue value is set to the maximum of 255. The maximum number of colors that you
can therefore find in a standard RGB image is 16.7 million — 256 × 256 × 256.
When all three of the red, green, and blue components are set to zero, you have a complete absence of
color — black. Conversely, setting all of the values to the maximum of 255 results in white.
In this chapter you work with 8 - bit palette - based images, which allow you to use up to 256 of the
available 16.7 million colors in any one image. You also work with 24 - bit images — known as true color
images — which support the full range of 16.7 million colors in a single image.
Coordinate Systems
When you draw shapes and text in your image, you need to position them by specifying coordinates. If
you have a mathematical background, you ’ re already familiar with a graph type layout where the x and y
coordinates radiate to the right and upward from the bottom left corner, as Figure 17 - 1 shows.
y
x
Figure 17-1
With the PHP image functions, on the other hand, the coordinates radiate to the right and down from the
top - left corner, as Figure 17 - 2 shows.
x
y
Figure 17-2
The pixel in the top left - hand corner is at position (0,0). This means that, for a 300 - by - 200 - pixel image,
the top - right pixel is at position (299,0), the bottom - left pixel is at (0,199), and the bottom - right pixel is at
(299,199), as shown in Figure 17 - 3.
508
9/21/09 2:48:35 PM
c17.indd 508 9/21/09 2:48:35 PM
c17.indd 508