Lossless JPEG rotation

For a long time I’ve avoided rotating JPEG pictures in portrait format from my digital cameras — due to possible quality loss. Using the EXIF information software should be able to handle this, i.e. rotate pictures on-the-fly, but unfortunately this is rarely the case.

I finally decided to investigate if it’s possible to perform rotation without quality loss. The good news is that it’s possible, but it has some limitations. I found this in a very old JPEG FAQ (question 10):

“There are a few specialized operations that can be done on a JPEG file without decompressing it, and thus without incurring the generational loss that you’d normally get from loading and re-saving the image in a regular image editor. In particular it is possible to do 90-degree rotations and flips losslessly, if the image dimensions are a multiple of the file’s block size (typically 16×16, 16×8, or 8×8 pixels for color JPEGs). This fact used to be just an academic curiosity, but it has assumed practical importance recently because many users of digital cameras would like to be able to rotate their images from landscape to portrait format without incurring loss — and practically all digicams that produce JPEG files produce images of the right dimensions for these operations to work. So software that can do lossless JPEG transforms has started to pop up. But you do need special software; rotating the image in a regular image editor won’t be lossless.”

The next obvious question is: Which software supports this? Well, I was pleased to find that one piece of software that does that is Directory Opus. Quote from the forums:

“To perform lossless rotation the dimensions of the image must be an even multiple of the DCT block size (8) multiplied by the sampling size. The standard JPEG code defaults to a 2×2 sampling size (and Opus doesn’t change this) which means an image Opus outputs would need to have even multiple dimensions of 16×16”

In other words, right-clicking in Directory Opus and selecting “Convert Image” will let you losslessly batch-rotate pictures, as long as you select “Rotate” as the only option.

Here’s a list of other applications that support lossless rotation: Lossless jpegtran applications. Beware, Photoshop is not one of them. Neither is Explorer or Paint.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.