Lunch atop a (Springfield) skyscraper

Lunch atop a (Springfield) skyscraper
by andy-m                

Submit your Photo
Hall of Fame

Please participate in Meta
and help us grow.

Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Welcome to photo.SE, @drewk! – Reid Dec 15 '10 at 2:17
@Reid: Thanks!!! – drewk Dec 15 '10 at 3:58
Similar question on Super User suggests using program jhead:… – koiyu Dec 15 '10 at 10:30

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.

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

share|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
up vote 3 down vote accepted

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.

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

share|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)

share|improve this answer
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). – koiyu Dec 15 '10 at 10:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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