
Gifs - a little theory
The GIF file format was developed by Compuserve and is, sometimes, still refered to as Compuserve Gif. It uses the LZW (Limpel-Ziv and Welch) compression algorithm for 8-bit color images. It is the only image format supported by all graphical browsers.
The LZW compression algorithm contructs 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 do not have such color blocks. Hence, GIFs are more suited for line art and logos than other file formats.
Also, the algorithm counts the pixel change horizontally. Therefore, images that involve horizontal color changes will be larger than those that have vertical color changes.
The GIF compression algorithm is lossless, which means that no information is lost from the original image when its converted to a gif. (Note: If your original image contains more than 256 colors, then some information will be lost. However, once converted to a gif there will not be any further loss).
Gif Optimization
The file size of a gif depends on
1). The physical dimensions (width and height) of the image
2). The number of colors the image contains
3). The complexity of the image
Let us now look at each point individually and see how we can perform the optimization process.
Physical dimensions
All standard image editing programs come with a 'Crop' tool to remove any unwanted areas of an image. Using the Crop tool is quite simple.
In PaintShop Pro, click on the Crop tool icon
. Left-click on the image and drag a selection. You can also fine tune the selection by dragging the outline. When done, click on "Crop Image" button in the Control Palette.
In PhotoShop, click the Selection tool
. Left-click on the image and drag to select the region of interest. Click on the Crop button
or click Image - Crop.
The number of colors
Gifs can contain a maximum of 256 colors. The more the number of colors, larger the image size taking longer time to load. Reducing the color depth obviously involves a tradeoff in the presentation of the image, however, most of the times, your gifs will look just fine.
Here are a few examples on controlling color depth. Note the difference in file sizes for each image.
4 color gif: 234 bytes
256 color gif: 998 bytes
8 color gif: 275 bytes
256 color gif: 1044 bytes
4 color gif: 521 bytes
8 color gif: 706 bytes
16 color gif: 907 bytes
256 color gif: 1896 bytes

6 color gif: 879 bytes
16 color gif: 1384 bytes
64 color gif: 3288 bytes
Reducing the number of colors with Paint Shop Pro (version 5)
Reducing the number of colors with Corel Xara
To save an image in Corel Xara (version 2.0), click on File - Export and select .gif extension from the drop down menu. The Gif export bitmap options dialog box contains several options. You can control Dithering and choose color depth (8 bit, 4 bit or 2 bit). You can also specify the exact number of color you want in the image by clicking on the 256 (8 bit) radio button and entering the value in Number of Colors text box. You can select transparency and interlacing and the final dimensions of the image. Another helpful feature of the software is the preview button.
Reducing the number of colors with Adobe PhotoShop
When you Export a Gif image in Adobe PhotoShop version 5.0, the program provides a drop down menu through which you can select the number of colors in the final image. You can also choose the palette and transparency. Higher versions of the software are more suited for web graphics and have several options.
In the second part of this article, I'll describe how the complexity of the image determines its size. We will also probe deeper in GIF image optimization process by working on an example.