Lossless JPEG rotation

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:

  1. Start with the original JPEG photo.
  2. Rotate it once to the right using each program.
  3. Rotate a copy of the rotated photo back to the right using the same program.
  4. 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.

One thought on “Lossless JPEG rotation”

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *