Geek Stuff: Determining orientation of an image taken by iphone in your program

Even If you have not done any programming that involves image handling in ios environment you still may have noticed an odd behavior,that I am about to explain, while looking at pictures on other devices that were originally captured using an iphone.

Apple iPhone allows users to take picture while holding the phone at pretty much any angle. So these are the most common orientation of the phone while taking picture

No matter how you take the picture, it always shows up perfectly upright when you view it on your phone. However the odd behavior is that if you take the pictures in any orientation other than “0 Degree” orientation then most likely the image will not appear upright in most non-apple products (softwares).

Reason : This is because the camera is fixed to your phone. It cant rotate relative to your phone, so when you turn the phone to take the picture, the phone rotates relative to the view. When the shot is taken, camera grabs the bits and writes the view information onto the disk exactly as it saw it (i.e. not upright, if the phone was not at 0 Degree position). However, since your smartphone is not only a “smart” “phone” but also a very “smart” “camera”, along with the picture information, it also writes a property called Orientation which can tell how to rotate the picture to actually see it upright.

Since this was something introduced by Apple, all their software understand the orientation property and ‘behind the scene’ takes care of rotating the picture but looks like its going to take sometime for everyone else to catch up. Even if and when they do, users will have to upgrade the software to get this issue corrected. I am surprised to see the number of forum threads about this problem, including a lot of development forums (https://www.google.com/search?gcx=c&ix=c2&sourceid=chrome&ie=UTF-8&q=iphone+image+orientation+problem)

So heres my 2 cents on the issue and how to take care of it in your software..

Depending on your programming environment you may use a different program but I am using godsend/awesome-human-created ImageMagick. Using the identify command of IM (with the verbose option) I see something like this (partial screen)

As you can see there is a property that shows the Orientation of the image. Here are the values for all 4 angles

: 0 Degree

: +90 Degree

: -90 Degree

: +180 Degree

So basically it boils down to,

a) Rotate +90 if you see Orientation = Right Top

b) Rotate -90 if you see Orientation = Left Bottom

c) Rotate +180 if you see Orientation = Bottom Right

d) Do nothing to fix orientation if you get Orientation = TopLeft

Hope it helps!

No comments yet.

Leave a Reply


+ 4 = six