What everyone should understand about JPEG.

All of us use JPEG files these days. You may be emailing a file for publication, or perhaps using a digital camera while on vacation. Like all things digital there is a certain magic to it all. But there is also a dark side. Understanding the JPEG format is your only protection.

Why JPEG?

The whole reason behind the JPEG file format is to make smaller computer files. Uncompressed photos can be huge data files. By storing the photographic data in the JPEG file format it is possible to reduce the size of data file by as much as 90%. The phrase "as much as" is the critical part of the previous statement.

There are two important aspects of JPEG that you need to consider before saving a file using the format. Both of these relate to the "lossy" nature of JPEG — it actually changes the image and removes some of the original image data. How this affects the image is controlled by these two key aspects: the type of image and the amount of compression.

Please note that any compressed image (JPEG, PNG, etc.) will not further compress when included in a ZIP or SIT archive. In fact, the kind of compression that ZIP and SIT apply is not very effective on photographs at all. (See our page on using ZIP and SIT files)

1. Only photographs.

FIGURE 1: Effects of JPEG on Solid Colors with sharp edges.
Sample image not suited to JPEG. Sample image not suited to JPEG. Sample image not suited to JPEG. Sample image not suited to JPEG.
JPEG file set to maximum quality. File size: 2,507 bytes JPEG file set to medium quality. File size: 1,268 bytes JPEG file set to low quality. File size: 794 bytes PNG file format. File size: 797 bytes
First, use JPEG with the right kind of image. Only store images that are "photographic" in nature. The key characteristic of photographs is that there are very few sharp color changes. JPEG does not compress non-photographic images very well and will severely damage the wrong kind of image. As you can see in Figure 1 only the lowest quality JPEG can match the standard PNG file for compression. Notice the blurry area between the colors in the JPEG file with the smallest file size. This is simply the wrong kind of image to save as JPEG.

FIGURE 2: To see a detailed enlargement of the effect of compression on this face, click the image. (It is really big.)

2. Quality versus compression.

This second aspect of JPEG involves two competing goals: file size versus image quality. Most digital cameras will give you controls that affect the basic parameters of the image file. One is the resolution (or how many pixels to use when capturing the image) and the other is how to save the image. For resolution, you might as well use all the pixels your camera gives you. Unless you bought some zillion dollar camera, there is never enough pixels. (In my little Canon camera the resolution is stated as Small: 640 x 480, Medium(1): 1024 x 768, Medium(2): 1600 x 1200 and Large: 2048 x 1536. The numbers represent pixels across by pixels down. So let's figure that the resolution you use will always be the same - the most you can get.

Once you capture an image it simply becomes a file on some sort of computer storage medium. The storage medium might be a Flash Card or Memory Stick (static RAM) or maybe a tiny hard disk, regardless — your digital photo is just a computer file. Most consumer digital cameras do not even ask you what type of file format to use when saving your photo, today they generally use only JPEG.

FIGURE 3: My imaginary JPEG Quality vs File Size Scale
My JPEG Scale

So how do you get the most quality out of the JPEG format? Most cameras have some way of setting the quality level of the saved images. They usually do not say it so bluntly, but I will. When I hear “JPEG” I immediately think of the scale shown in Figure 3.

In practical terms, each camera make comes up with their own terms. My little Canon camera uses the settings: Normal, Fine, and Superfine. I do not know for a fact, but I image those settings landing on my scale (Figure 3) where the red dots are positioned. I always use Superfine.

What about Image Editing Software.

FIGURE 4: JPEG Control from Adobe Photoshop
JPEG Controls from Photoshop CS

In Adobe Photoshop you make this decision with the dialog box in Figure 4. I think this strange combination of a slider, a numeric input and a dropdown menu is confusing, but whichever control you use, the other is affected. (In other words you cannot select Quality: 10 Maximum and have the pointer at the "small file" end of the slider.)

I image that most image editing software has some sort of choices like these, although you may have to look hard for the settings.

By they way, nearly everything about JPEG files has a parallel in MPEG sound and video files.

A note about file formats.

There are other file formats that you can use. They are not always available in any give device or program, but when available they are often a better choice than JPEG. PNG and TIFF are two that are quite common. These are non-destructive and generally more versatile.