How Does GIF Compression Work?
How GIF Compression Works
When you start talking about image compression, you usually need a strong cup of Joe and a bullhorn to stay awake. My goal here is to relate the process of GIF compression in a way that makes sense, no caffeine required. You’re welcome.
We all know that images are made of pixels, and pixels are nothing more than tiny squares of color that make up an image. Let’s look at this example of a simple GIF image.
If we assign values to the pixels where: Blue = x Red = y Green = z, now we can describe this image row by row. The first row is all blue, so five x’s would represent the five blue pixels in the first row. The following rows are a little more complicated:
When a GIF is compressed, the description could look more like this:
As you can see, longer stretches of a solid color make the file more compressible (lines 1 and 5 are the most compressed) and speckled images cannot compress (line 3 is not compressed at all). When the color changes with each pixel in a row, there is no shorter way to convey the information.
Our 5×5 GIF does not seem too complex, but you can see how it reduces the character count and, therefore, the amount of data needed to describe the image. This results, obviously, in a smaller file size for the same information.