JPEG is a lossy format, and naive rotation results in a loss of quality. JPEG does allow some lossless operations, such as rotation by 90 degrees and flipping, on the basic blocks (MCUs) that compose the image. It also allows re-arranging those blocks. Using this lossless operation, it is possible to perform a lossless JPEG rotation. To do so, the rotated image must meet some basic criteria, such as having its size be a multiple of the MCU size (usually 16×16).
Not all programs perform a lossless JPEG rotation, so it is useful to be aware of which ones do. I checked a couple of commonly used programs to see if they indeed perform lossless rotation. The testing procedure was:
- Start with the original JPEG photo.
- Rotate it once to the right using each program.
- Rotate a copy of the rotated photo back to the right using the same program.
- Compare the results using ImageMagick (
compare -metric ae).
Results
Gnome’s Image Viewer 3.14.1 is lossless.
digiKam (4.4.0) is lossless; however, rotating with digiKam’s Image Editor is lossy.
Shotwell (0.20.1) does lossy rotation.
Thanks for looking into this.
I wonder it rotation is possible based on EXIF data alone (which sometimes includes a rotation field).
I guess that would require every viewer to recognize such data.