GIF Compression

There are two main things to know about GIF compression. First, it is a “lossless” compression, meaning no image information is lost in the compression process, and the decompressed image will be identical to the original. (Note that some information may be lost in the conversion process from RGB to GIF format, but once it is converted, the compression itself is lossless.)

Second, GIF uses LZW (Lempel-Zev-Welch) compression, which takes advantage of repetition in data streams. Translated into graphic terms, this means that LZW compression is extremely efficient at condensing rows of pixels of identical color. To use a simplified example, when the compression scheme hits a row of 15 identical blue pixels, it can store the information as “15 blue,” but when it encounters a row that has a gentle gradation from blue to black, it needs to store a description for every pixel along the way, therefore requiring more data. This is why GIFs are efficient at storing simple graphical images; the areas of flat color take advantage of the LZW compression.

On a historical note, Unisys, the company that holds the patent on LZW compression, caused quite a stir on the Internet in 1994 when they announced that it would begin charging licensing fees to developers incorporating GIF compression into their products. In the face of fees and legal hassles, the Internet population rushed to find nonproprietary alternatives to the GIF format, leading to the development of PNG (see Chapter ...

Get Web Design in a Nutshell 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.