The Ever-worsening JPEG Phenomenon
JPEG files are by far the most common image format used for photography on the web and for good reason. The JPEG format does far better at retaining color fidelity than does GIF. For continuous-tone images such as photos, JPEG's can also be a lot smaller than GIF's due to the way the data is stored. It's not uncommon for JPEG's to compress 10:1 or even 20:1, whereas photos stored as GIF's top out at around 5:1. Of course the GIF format does work better for line art and graphics with large single-color areas, but that's not what this tip is about.
The most important thing to keep in mind is that JPEG is a lossy compression algorithm, meaning that every time you save a JPEG, you are losing information in the process of compressing it. Open a JPEG again, tweak something, then resave it and it gets even worse. Do it a third time, worse still. The file sizes will still be about the same, but the images will look worse and worse. This forces you to try saving the image with less compression to try to keep it looking decent which of course makes your file sizes bigger which defeats your whole purpose.
How do you get out of this vicious cycle? Easy: Never open a JPEG, edit it and resave. Instead, always go back to your original PSD, TIFF, NEF or what have you to make your changes, and then resave as JPEG. The JPEG is your original you say? Before you do anything else, save it in some lossless format and now you can pretend that that file is your original.
For the truly curious, there technically are a few things you can do to JPEG's that will not degrade them. First off, a few details (and only a few) about how JPEG's work. The process takes advantage of the fact that the human eye is not as dependent on subtle transitions of tone to distinguish an image as it is more abrupt changes. JPEG processes an image in blocks of typically 16x16 pixels (but occasionally 8x8 or even 8x16). Within each block, it attempts to smooth out the more subtle transitions even more without disturbing the edges that define objects in the image. When editing an image, as long as you don't disturb these blocks, no harm comes to the image. But avoiding doing so isn't easy.
Certain specialized editing programs can take advantage of this block structure to perform tricks with JPEG images without expanding and recompressing them. Rotations of 90 or 180 degrees in either direction can be done relatively easily. It is also possible to crop an image so long as it is done on block boundaries beginning in the upper left hand corner. Keep in mind that in most programs including PhotoShop won't do this. Windows XP now has a graphic viewer that will let you rotate images as well, but you should resist the temptation. As with PhotoShop, you will actually be decompressing the image, rotating it, then resaving with the accompanying loss of quality that comes with it. ACDSee is the most popular program that actually offers lossless JPEG rotation. A free online service that can do lossless JPEG rotation is available online as well, courtesy of Pegasus Imaging.
You can also take advantage of the block structure when making localized edits to your images in any program, so long as you resave it with exactly the same settings that were used to save it the last time. Same compression level, same everything. Exactly the same. Otherwise, you'll still be losing ever more information each time you save. If you don't change any settings though, any blocks that were unmodified should compress again the same as or nearly the same as previously, with any significant degradation being limited to areas of the image that were changed. Keep in mind that any global changes such as brightness, contrast, tone adjustment, white balance or sharpening will affect all blocks and result in quality loss no matter what program you use. As was stated previously though, your best option is to stick with PhotoShop's native PSD or other non-compressed format for all your editing.
JPEG's lose more information with greater degrees of compression as well, which does make sense since the file size gets smaller. Once this information has been lost, it can never be restored. Simply saving a JPEG that had been compressed down to a 30 quality level at 90 will not restore the missing details. Regardless of what compression setting you chose you will always lose at least a small degree of detail. Even saving a JPEG at 100 quality setting will not avoid this, but it will increase the file size significantly. The original JPEG standard did provide for a lossless option, but it is no longer supported by any current software.
Mt. Rainier after being subjected to repeated JPEG compression
The image above contains four versions of Mt. Rainier, one of my favorite subjects. Obviously since you're reading this on a web page, the entire image is itself a JPEG. More importantly though, the version on the left is the original, and each successive rendition has been passed through my JPEG torture test more and more times. Each iteration consisted of opening the JPEG created in the prior torture session, shifting the image over and down by 2 pixels using PhotoShop's "Offset" filter, then resaving the result as a low-resolution JPEG. Given JPEG's use of 8x8 (or larger) blocks, the shift operation was designed to inflict a much pain as possible on my subject in order to illustrate what's happening. In succession, the images have survived one, five, and finally ten torture sessions. Notice how much of the finer details have become progressively muddied, finally ending up with a version that itself is almost torture to look at. My apologies for subjecting you to it. Hopefully now though you will feel motivated to join the Society for the Prevention of Cruelty to JPEG's.
Do be nice to your JPEG's.