Skip to Content

Fix iPhone EXIF rotation from the command line

My iPhone is the camera that i use more than any other, but there's one thing that has consistently annoyed me about it. Apple uses an EXIF tag to rotate images. This can be a problem when you share images with others. Safari will rotate the image correctly, but no other browser will.

Adding to the trouble is that Mail.app and the Finder will also "auto-correct" the rotation, so it can be hard to tell which images need to be "fixed" and which don't.

You could use the '/usr/bin/sips' program (sips --rotate 90 picture.jpg) if you knew which pictures need to be corrected, and which direction they need to be rotated (clockwise or counter-clockwise). But I wanted something that would, as they say, "just work."

(I also wanted something I could use on my webserver, which runs Linux, but that's really a side issue.)

My attempts to find a solution on Google were fruitless, so I asked on Twitter. Michael Baltaks pointed me to jhead, which describes itself as a "Exif Jpeg header manipulation tool" which includes the source code as well as pre-built binaries for OS X, Linux, FreeBSD, and even Windows.

To fix a picture named "image.jpg" just type "jhead -autorot image.jpg" and you will see "Modified: image.jpg". You can fix all JPGs in the current folder using "jhead -autorot *.jpg" and it will only change the images which have the EXIF tag.

Note: You might be tempted to use the "-norot" argument, which will "zero out" the rotation tag, but it will not have the desired effect, and (even worse) once you have used the "-norot" you can't use "-autorot" -- trust me, I learned that one the hard way.

Categories

UNIX / BSD iPhone

My iPhone is the camera that i use more than any other, but there's one thing that has consistently annoyed me about it. Apple uses an EXIF...
 

Add a Comment

*0 / 3000 Character Maximum

8 Comments

Filter by:
timdoug

A Mac OS X binary that's also PowerPC, 32-bit x86, and 10.4 compatible I've just compiled and posted here:

http://www.timdoug.com/etc/jhead.gz

Cheers!

February 17 2010 at 11:17 PM Report abuse rate up rate down Reply
Craig Stanton

a bit more info. The cameras I have experiences this on are:

Canon PowerShot S50
Canon 350D ("Rebel" in some countries)
Canon IS710
(plus the iPhone)

I know that's only three and only Canon and Apple but, I'm pretty sure it's the standard way for all cameras with orientation sensors.

But you're right, I still use jhead to do the rotation so that other things that aren't Exif compliant can understand it and so that iPhoto only stores one copy not two. Two other commands I like from jhead are "-dt" to delete the thumbnails that are built into the jpeg, saves just a few kilobytes per image and "-ft" which sets the modification date of the image to that which is stored in the Exif date. Since only some of the files will have been modified by -autorot you'll have some of the images with their original date and some with the time you ran -autorot

February 17 2010 at 5:13 PM Report abuse rate up rate down Reply
Craig Stanton

Right is right. You may say that exif is pointless because no one understands it (you'd be wrong because the digital cameras I have used understand that same rotation flag just fine), but Apple's implementation of it is not broken.

That's like saying you're fixing Text Edit's broken rtf implementation so that Browser X can read it, coz Browser X only understands html.

February 17 2010 at 4:56 PM Report abuse rate up rate down Reply
Craig Stanton

I don't think you're quite "fixing" exif rotation here. The exif tags that Apple sets are correct. It's just that the other browsers are ignoring them, so you have to rotate the image data.

February 17 2010 at 1:03 PM Report abuse rate up rate down Reply
3 replies to Craig Stanton's comment
fellowweb

Best articles on TUAW for weeks! Thank you very much. Really helpful, technical note!

February 17 2010 at 12:26 PM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.