Table of Contents
Overview
RGB Model
Indexed Color
Transparency
HSV/HSL Model
This chapter describes color palettes used in PHP.
Overview
A palette, in computer graphics, is a designated subset of the total
range of colors supported by a computer graphics system. Each color in
the palette is assigned a number, and for each pixel, one of these
numbers is stored. This number determines the color of the pixel. [1]
[http://pterodactyl.l2p.net/book/php5image/page/bi01.html#wikipedia]
Colors can be assigned in numerous ways, but PHP supports only few of
them.
RGB Model
The RGB color model is an model in which red, green, and blue are
combined in various ways to reproduce other colors. The name of the
model and the abbreviation "RGB" come from the three primary colors,
red, green, and blue. [1][http://pterodactyl.l2p.net/book/php5image/
page/bi01.html#wikipedia]
We shall deal with 24-bit RGB. Often known as true color and millions
of colors, 24-bit color is the highest color depth normally used and
is available on most modern display systems and software. Its color
palette contains 16,777,216 colors. [1][http://pterodactyl.l2p.net/
book/php5image/page/bi01.html#wikipedia]
Colors in RGB are assigned using integers in range from 0 to 255 for
red, green, and blue, where 0 means total absense of color and 255
means full intensity of color. So (0, 0, 0) will give black and (255,
255, 255) will give white. Red is (255, 0, 0), green is (0, 255, 0),
and so on.
Figure 4.1. The RGB color model mapped to a cube
[http://pterodactyl.l2p.net/images/RGBCube.png]
The RGB color model mapped to a cube
The image from Wikipedia, the free encyclopedia.
Indexed Color
Indexed color is a type of color space for digital images. Whereas an
RGB image specifies a red, green, and blue value separately for each
pixel in the image, an indexed color image maintains a table that
defines a number of predefined colors, and each pixel refers to a
color in that table. [1][http://pterodactyl.l2p.net/book/php5image/
page/bi01.html#wikipedia]
Indexed color is limited to 256 colors (or 16 colors in a smaller
palette), which can be any from the set of 16.7 million 24-bit colors.
[7][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#indexed.color]
Indexed color can greatly reduce file sizes for images - especially
large ones - using only a few different colors. If an indexed color
image has too small of a color table, however, gradients and other
shadings can appear blocky. [1][http://pterodactyl.l2p.net/book/
php5image/page/bi01.html#wikipedia]
Figure 4.2. Indexed Color Image
Original Image: 59.7 Kb
[http://pterodactyl.l2p.net/images/ICOriginal.png]
Original Image: 59.7 Kb
Indexed Image: 21.7 Kb
[http://pterodactyl.l2p.net/images/ICIndexed.png]
Indexed Image: 21.7 Kb
[Note][http://pterodactyl.l2p.net/images/docbook/note.png] Note
Indexed color is usually used only with the RGB color model. [1]
Transparency
One color entry in a single image's palette can be defined as
"transparent" rather than an actual color. This means that when the
decoder encounters a pixel with this value, it is rendered in the
background color of the part of the screen where the image is placed.
[1][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#wikipedia]
In addition to full transparency described above, partial transparency
also enabled using the concept of an alpha channel. In a 2D image
element which stores a color for each pixel, an additional value is
stored in the alpha channel containing a value ranging from 0 to 1. A
value of 0 means that the pixel does not have any coverage
information. A value of 1 means that the pixel is fully opaque. [1]
[http://pterodactyl.l2p.net/book/php5image/page/bi01.html#wikipedia]
Figure 4.3. Partial Transparency
[http://pterodactyl.l2p.net/images/Transparency.jpg]
Partial Transparency
HSV/HSL Model
The HSV (Hue, Saturation, Value) model, also known as HSB (Hue,
Saturation, Brightness), defines a color space in terms of three
constituent components: Hue, the color type (such as red, blue, or
yellow), Saturation, the "vibrancy" of the color, and Value, the
brightness of the color. [1][http://pterodactyl.l2p.net/book/php5image/
page/bi01.html#wikipedia]
Figure 4.4. An HSV color wheel
[http://pterodactyl.l2p.net/images/HSVTriangle.png]
An HSV color wheel
The image from Wikipedia, the free encyclopedia.
HSL is similar to HSV. The HSL color space, also called HLS or HSI,
stands for Hue, Saturation, Lightness (also Luminance or Luminosity) /
Intensity. [1][http://pterodactyl.l2p.net/book/php5image/page/
bi01.html#wikipedia]