GIF's and JPEG's

Why and When GIF or JPEG

Simplified:

  1. GIF's compress the file on a left to right basis.
    Each information unit about color starts with a change. The color is specified as is the number of pixels to the right with the same color. Not until the next color change is there more data about color. So if a line of pixels is all one color left-to-right the amount of data added to the file is very small. If the color keeps changing (as in a photograph) each different pixel adds information to the file.
    See the large difference in file-sizes for the horizontal gradation image compared to the vertical gradation image.
  2. JPEG's compress the file by averaging pixels around a set number of points.
    Photographs have all kinds of color changes even in areas you might think are pretty similar, such as clear skies. So file size and image quality are related to the number of sample points (basically). Note that in both images the horizontal and vertical gradation produce a file with about the same size.

For almost all purposes when you have a photograph use JPEG's and when you have graphics with flat colors use GIF's. The reason many photos are still GIF's on the web is historical. At first there was no support for JPEG's. But once JPEG's were available, at various rates of compression, they were and are vastly superior for most photographs.
  Horizontal Gradation Vertical Gradation
GIF's
GradGIFsampHorizontal.gif
31 kb
GradGIFsampVertical.gif
7 kb
Graphic_VCut.gif
1.6 kb
JPEG's
GradJPGsampHorizontal.jpg
7 kb
GradJPGsampVertical.jpg
6 kb
mataF05308aVCut.jpg
11 kb
  Two images of the same (cropped) screen capture - at 817 pixels horizontal by 538 pixels vertical.  

GIF

34.3 kb

 
  The JPEG version of the file (below) is almost 4.6 times the size of the GIF version (above) because of the solid colors (no gradations). This works much more efficiently to compress as a GIF than it does to compress as a JPEG.  

JPEG

157 kb