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.
Share
Categories
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
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!
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
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.
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 Permalink rate up rate down ReplyBest articles on TUAW for weeks! Thank you very much. Really helpful, technical note!
February 17 2010 at 12:26 PM Report abuse Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Refurb Apple MacBook Air Laptops: 12" 64GB SSD for $699 + free shipping
- JVC Motion Sensing Clock Radio with Dual iPod Docks for $55 + free shipping
- Apple iPhone Headset with Mic for $4 + $2 s&h
- miFrame Picture Frame Dock for iPad for $64 + $8 s&h
- Refurb Apple iPod nano 8GB MP3 Player for $99 + free shipping, 16GB for $119
- Hannspree Apple-Shaped 28" 1080p LCD HDTV for $270 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



8 Comments