how to work with jpeg files.

JPEG files are everywhere, but working with JPEG files requires a little understanding about how the format works. Without this understanding it is all too easy to make mistakes that cause permanent damage to pictures saved in this format.

Jpeg Compression Example
JPEG: A photo of a flower compressed successively more from left to right.

JPEG stands for Joint Photographic Experts Group. The format was designed to facilitate efficient handling of photographic image files by using an algorithm that reduces file size with minimal cost to image quality.

Reduced file size is important because it speeds up the transfer of information from point to point, whether from digital camera to memory card, card to computer, or computer to any other destination. Without the efficiencies made possible by the JPEG format, transferring images from point to point would take much more time, and require substantially more storage space to contain them.

If efficient transfer and storage of large digital files were not an issue, the JPEG format might never have been invented. But it is an issue, and when properly used the compromises are vastly outweighed by the benefits. The key is knowing how and when to use the JPEG format so that image quality is compromised as little as possible.

JPEG is a compressed format. The image data in a JPEG file is manipulated in order to reduce file size. The reduction can be substantial; 10, 20, even 100 times smaller than the original uncompressed image file. The 'cost' to image quality ranges from undetectably small, to rendering an image virtually useless. The goal in working with JPEG files, especially as it relates to high quality photographic imaging, is to keep the cost to image quality in the 'undetectably small' column. This is easily accomplished by using JPEG at the right time and in the right way.

It helps to understand how the JPEG format actually works, and how it differs from an uncompressed format like TIFF or PSD (Photoshop file format). The data in an uncompressed image file is stored pixel-by-pixel; each pixel is accompanied by a unique set of data describing it. This is true whether an image has 10,000 different color pixels, or 10,000 pixels that are identical, or nearly identical, in color; each pixel has a unique set of data describing it.

The JPEG format takes a much different approach to storing pixel data. Rather than assigning a unique set of data to each pixel, it maps the location of pixels that are identical (or near identical) in color and stores that information just once. When a JPEG file is opened, the location map is used to assign colors back to each pixel. This is why an unopened JPEG file might report a file size of 1MB and when opened in Photoshop report a size of 6MB.

To illustrate the efficiency of this strategy, consider this: a one-color picture containing 10,000 pixels can accurately be described with a single set of data - the data for one color. An uncompressed file would contain 10,000 sets of data. That's how JPEG realizes such huge reductions in file size.

Of course photographic images are made up of many hundreds to many millions of different colors, but the JPEG compression is the same: identify the location of like colors, map their location, and store that information just once for each color.

If you shoot in JPEG format with your digital camera, this explains why file sizes vary so much from shot to shot. Simple scenes, say a blue sky over the ocean, result in a much smaller file size than a mountain meadow full of wildflowers.... even though the number of pixels used is exactly the same. The greater the number of colors contained in a scene, the larger the JPEG file.

The terms used up to this point, 'nearly identical color' and 'like colors', are important to our understanding. The JPEG format allows us to choose a level of compression from 'low' to 'high'. The higher the compression, the smaller the resulting file. In order to achieve the highest possible compression, the JPEG format takes a little liberty in what it considers to be a 'single' color. Colors that are 'close' to being the same are grouped together and defined by one set of data saying they 'are' the same. This can save a considerable amount of space. At 'low' compression, JPEG takes fewer liberties in grouping. Thus, the lower the compression, the higher the accuracy of the colors.

Color grouping is illustrated nicely in the photograph of the flower at the top of this article. Depending on the level of compression, the result ranges from visibly undetectable to grossly unacceptable.

Variable compression levels serve to address many different needs, from extremely small files required for use on the Web, to extremely high quality files used for photographic printing. In Photoshop, the range of compression is on a scale from 1 to 12. Somewhat confusingly, 1 equals maximum compression and 12 equals minimum compression. There is no single right way to use compression, just different ways to use it for each type of application.

This is a brilliant strategy for reducing file size while maintaining image quality, but not without flaws. The biggest issue is what happens when a JPEG file is repeatedly opened, edited, and re-saved. In many cases, each time a JPEG file is re-saved, the compression scheme kicks in anew. Two very close colors from the first JPEG save, might be grouped into a single color on the next. Do this enough times, and image quality will degrade.

Because image quality can take a hit with each save, and repeated JPEG saves ultimately can degrade an image, it's wise to use JPEG when necessary and other, non-compressed formats like TIFF or PSD when it's not. It's not possible to define one set of rules that apply to every workflow or application, but it is possible to state one general rule: Don't re-save a JPEG unless it is necessary.

There are some exceptions. Depending on what type of editing has been done to an image, a re-save may not cause quality loss. Simply rotating an image 90 degrees is an example. There are others. But unless there is a need to edit and re-save in JPEG, an uncompressed format like TIFF is a better choice for images that are in the process of being edited.

A typical workflow, and the one we use for image editing, is this: Files received in JPEG format are opened and immediately re-saved as TIFF's or PSD's. All subsequent editing work and re-saves are done in one of these un-compressed file formats. These are considered 'working files'. The working files are not re-saved as JPEGS until editing is complete and they are ready to enter into production for printing, where efficiency becomes a priority. Following this workflow prevents a file from being re-saved as a JPEG more than once after it is received.

Every workflow that includes handling of JPEG files should be managed in a similar fashion. JPEG should be used when required due to transfer speed or storage space, and avoided at other times. Use of the JPEG format has many advantages and when used carefully, has its rightful and respected place in the imaging world.

It is worth noting that original camera files, regardless of file format, should always be kept in their original unedited form, saved/archived to CD or DVD disk. This gives you future access to the original unedited files. Simply copying or moving a JPEG file (or any file for that matter) from one location to another has no effect on the data.