Why You Should Always Rotate Original JPEG Photos Losslessly

Recognize the warning message above? It’s what Windows XP would show whenever you tried to rotate a JPEG image 90° using the Windows Picture and Fax Viewer. If you’re like me, you probably didn’t think twice about it (and checked the checkbox), since you had done it many times already and hadn’t noticed any difference in quality. After all, how hard can it be to turn a digital photo sideways? You just move the pixels around right?

Well, not really. The fact of the matter is, JPEG is a “lossy” compression algorithm that’s geared towards storing and sharing photos without taking up too much disk space. Rotating these compressed images is usually done by decompressing, rotating, and then re-compressing. Since the re-compression is lossy (i.e. data is thrown away), this process results in slightly degraded photos (hence that warning).

If you’re not convinced, check out this interesting experiment done by a Wikipedia user named Burny. Using a simple computer script, he took the following image and rotated it lossily 2000 times:

Here’s hows the image degraded through those 2000 rotations:

Pretty crazy, huh?

The term for this is “generation loss“: the loss of quality between subsequent “generations” of data.

Through multiple generations, photocopied papers, copied VHS tapes (remember those things?), and lossily compressed JPEGs all become muddled.

We’ve actually written about this subject a few times before. Here’s what happens if you save a JPEG (lossily) hundreds of times and what happens if you upload and download a YouTube video thousands of times.

Here’s what happens if you copy a VHS tape just 23 times:

In the same way, every time you rotate a JPEG lossily, you’re throwing away another fixed percentage of the data. It’s not much at first, but over multiple rotations this adds up.

As the Windows alert box suggests, you should always work on copies of your original files anyway. If you must rotate an original JPEG, try using a program that does it losslessly.

Don’t think you’re safe just because you use Windows 7 and the built in Windows Photo Viewer. While it generally does lossless rotations, in some cases it still functions lossily.

Matt Grum explains over on photo.stackexchange:

If the dimensions of the image are multiples of 8 (or 16 if chroma subsampling is used) then the rotations are lossless. Otherwise it is not possible to rotate the image without recomputing the blocks i.e. recompressing the image, which is lossy.

The reason for this is that jpeg images are broken up into a series of 8×8 or 16×16 blocks which are compressed individually. Incomplete blocks are only allowed on the right edge and bottom edge. Thus is your image is not an exact multiple of 8/16 it will contain incomplete blocks, which will end up on the wrong edge after rotation.

The good news is, most modern digital cameras produce photos that allow for this lossless rotation, so this isn’t an issue that will affect most of your image handling (it’s still good to be aware of, though).

Finally here’s another solution to this lossless/lossy problem: shoot RAW. You can spawn as many JPEG photos as you want from your RAW files, and then rotate them to your heart’s content!