Colors and the Web Browser

Images displayed on monitors with a limited number of available colors (typically 256) will be dithered when they are rendered. Netscape and Internet Explorer on Macintosh or Windows systems support a 216-color “web-safe” palette that will be accurately represented on all systems. These 216 colors are a subset of the Macintosh’s 256-color system palette; the extra 40 colors are different from colors found in Win32 standard palettes. Colors not in this safe palette will be dithered to varying degrees on 8-bit systems. The 216 colors of the web-safe palette may be modeled as a 6 × 6 × 6 color cube.

Browsers running on Unix platforms running the X11 window system will sometimes use the 6 × 6 × 6 cube (216 colors), a 5 × 5 × 5 cube (125 colors), or even a 4 × 4 × 4 cube (64 colors), depending on how many colors are available to the browser. On an 8-bit system, Netscape may be run with the -install option specified on the command line to start the browser with the 216 color palette.

In later chapters, we will be writing scripts to generate graphics that are to be displayed on web browsers using this limited palette. These scripts will often need to allocate colors in the color table of the image. You may find it useful to have a utility script for computing the nearest color in the 6 × 6 × 6 color cube given a list of RGB values.

The 216 colors of the 6 × 6 × 6 color cube are those for which each of the red, green, and blue values are either 00, 33, 66, 99, ...

Get Programming Web Graphics with Perl and GNU Softwar now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.