The Gif file format uses the LZW compression algorithm developed by Abraham Lempel, Jakob Ziv and Terry Welch. The compression algorithm constructs a color table for an image wherein each color value is matched to a pixel. Thus, images with large areas of one color will be compressed far better than those that those that do not have such color blocks.
It, therefore, follows that simple images and graphics like line art and logos are better saved as Gifs as they are likely to contain areas of single flat color and hence will be compressed more. Photographs on the other hand are much more complex images and the LZW algorithm cannot compress these very well.
Let us take a look at two example. Note the file size and clarity (or quality, if you like) of the images below.
Simple image that contains areas of flat colors is compressed well by LZW algorithm: Only 1,110 bytes
Complex images are those without areas of flat color and generally contain many colors. The LZW Gif compression algorithm cannot reduce the file sizes of such images well: 17,848 bytes
One more point on the LZW compression algorithm – it counts the pixel change horizontally. Therefore, images that involve horizontal color changes will be larger than those that have vertical color changes. Take a look at the two example images below:
An image with little horizontal color change: 324 bytes
An image with a significant amount of horizontal color change (It is the two differently colored vertical bands that cause so much of horizontal color change): 1109 bytes
And since we are on this point, what if, instead of 2 colors (as in the images above), there were several colors? Let us compare the file sizes:
You’ll notice that the image that had lesser horizontal color change (the one with horizontal color bands), almost doubled in file size while the one in which we had vertical color bands increased only about 15%.
Finally, the GIF compression algorithm is lossless, which means that no information is lost from the original image when its converted to a gif. Since we know that a Gif image can have only 256 colors, if your original image contained more than 256 colors, then some information will be lost. However, once converted to a gif there will not be any further loss.
We’ll discuss these points in detail along with examples in sessions on optimizing GIFs.
By the end of the first quarter of 2012, sales of the iPhone had surpassed the total sales of Microsoft from all its products and services. This small device has actually made Apple the most valued company on the planet. [more...]