I am organizing a group of old images on OS X. Many are JPEG and predate the EXIF tag for camera rotation. Of course, many tools degrade the image (Question '10') if you edit the image. It is possible to rotate losslessly however.

I am considering writing a quick Automator action that will allow an image to be rotated -90 / 90 degrees based on seeing the image in the Finder and I would use either the Automator action or the command line sips to do so.

So does anyone know if the sips command or the Automator action rotates losslessly?

| improve this question | | | | |

You can rotate losslessly with NConvert which is available for many platforms including the Mac. It is a command line tool, which is invoked similarly to this:

nconvert -jpegtrans rot90 DSCF0001.JPG

On a Mac, the syntax may be different, I don't know but if you can invoke a command line program from your Automator, then you're probably set.

BTW, XnView is an image viewer which an do batch conversions and output batch files that will invoke NConvert for you. This is not the answer you are looking for but you can consider it if you want less work.

| improve this answer | | | | |

Correct me if I'm wrong, but I was under the impression that whether a JPEG could be rotated losslessly depended on the exact dimensions.

The reason being that a JPEG image is divided up into a series of 16x16 pixel blocks (or 8x8 without chroma-subsampling), each of which can be rotated individually without having to re-encode. The top left corner of an image must lie on a block boundary but the bottom right corner doesn't. Rotating an image whose size is not a multiple of 16 would cause problems as the top left corner would no longer be on a block boundary and thus all blocks would have to be recomputed.

| improve this answer | | | | |
  • Yes, exactly. Also the rotation needs to be in a 90Deg increment. BUT -- your software needs to do it that way. Photoshop, Aperture, Automator, Preview, most other image editors or DAMs do NOT do it that way. They take the JPG file, uncompress to a common editable format (TIFF is common), perform whatever action, resave in the requested format which requires re-compression. Look at the link in my OP... – drewk Dec 17 '10 at 0:17

Thank you for all the answers here, I really appreciate it.

I found a different solution that I wanted to share. Jpegtran does lossless transforms of jpeg images. I discovered it when I installed ImageMagick and it is part of the tool set installed.

To use, type:

jpegtran -rot 90 DSC_0276.jpg > DSC_0276-rot.jpg

Then you can trash the original file. I wrote a script to allow me to click a rotate button in the finder and boom. Rotated and the original is sent to the trash (recoverable if there is an error)

You can also use ImageMagic itself. ImageMagic has an "auto-rotate" option that will read the EXIF header and rotate the JPEG image to the same as the camera's gravity sensor. The EXIF header is then modified. That command is:

convert -auto-orient DSC_0276.JPG DSC_ROT.JPG

Or use ImageMagic to rotate:

convert -rotate "90" DSC_ROT.JPG DSC_ROT.JPG

ImageMagic can work on the file in place; ie, convert [options] INFILE OUTFILE where INFILE and OUTFILE can be the same name. jpegtran needs two separate file names and you need to have a script or other workflow to account for that.

ImageMagic's -auto-orient is definitely lossless and I believe the 90, 180 ,270 degree rotations are lossless. I cannot guarantee that.

jpegtran only does lossless transforms.

You can use MacPorts to install these.

| improve this answer | | | | |

I'll provide an answer for Windows users in case any come looking for an answer on Windows based on your question:

One of the plugins that comes with Irfanview does lossless JPEG rotations.

| improve this answer | | | | |

Is sips lossless when used for JPEG rotation? No.

sips doesn't modify the image in place but rather regenerates a new image.

You can use sips with no compression, but the result file will be bigger than the source file. To set the compression off ie. to set the quality to 100 %, give the parameter --setProperty formatOptions 100

For more sips options, consult the manual page by typing man sips in the command line.

(edited for clarity)

| improve this answer | | | | |
  • 2
    I think you misunderstood. The lossless JPEG rotation I am looking for does not uncompress or re-compress at all; rather it rotates the bit blocks so that the orientation changes with no change otherwise to the image. What you are suggesting is to resave the image at a lower compression, which does not solve the issue. Thanks tho! – drewk Dec 15 '10 at 4:03
  • I tried to answer the topic: "Is sips lossless when used for JPEG rotation?" Maybe simple "No" would have sufficed, but I also wanted to tell why :-) I'm rather new to the OS X ecosystem, so I really couldn't give you any alternatives which would be Automator or command line based (just yet at least). – Jari Keinänen Dec 15 '10 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.