Posts Tagged ‘EXIF’

(on Technorati , and Image Orientation

I was really puzzled… and in fact, I’m still puzzled, but at least it works now.

Update: I’m a bit less puzzled now. I wasn’t using the correct version of (see comments). This post has been updated to correct any information. I also updated the CODE style because posting python code when whitespace is ignored is a little confusing. ^.^

I’m now using for loading EXIF information from photos for my little project, PhotoFile. Today, I wanted the image orientation information. Looking in the source of, you’ll find:

0x0112: ('Orientation',
{1: 'Horizontal (normal)',
2: 'Mirrored horizontal',
3: 'Rotated 180',
4: 'Mirrored vertical',
5: 'Mirrored horizontal then rotated 90 CCW',
6: 'Rotated 90 CW',
7: 'Mirrored horizontal then rotated 90 CW',
8: 'Rotated 90 CCW'}),
0x9003: ('DateTimeOriginal', ),

So, I tried:

image = open("photo.jpg", "rb")
tags = EXIF.process_file(image)

Using tags["DateTimeOriginal"] works fine. But using tags["Orientation"] does not work. So finally (it took an unfortunate amount of time to do this), I tried:

for tag in tags.keys():
if "orientation" in str(tag).lower(): print tag

To correct the above, I’m a little lazy with composition, so it’s easier to just post some output from a python session:

>$ python
>>> import EXIF
>>> p = open("photo.jpg", "rb")
>>> tags = EXIF.process_file(p)
>>> for key in tags.keys():
... if "orientation" in str(key).lower() or \
... "datetime" in str(key).lower(): print key, ": ", tags[key]
EXIF DateTimeOriginal : 2006:03:19 14:22:40
Image DateTime : 2006:03:19 14:22:40
EXIF DateTimeDigitized : 2006:03:19 14:22:40
Image Orientation : Rotated 90 CCW

There is indeed no “Orientation” tag but there is an “Image Orientation” tag. The string “Image Orientation” appears nowhere in the source, and I couldn’t find any documentation on it. It looks like the tag keys are set by reading them from the EXIF information within the file appending the key to the classification (as pointed out by Shirley – see comments), but even the EXIF spec lists the tag as “Orientation”. If anybody knows why this is the case wants to clarify further, please post in the comments.


So if you’re using and want access to the image’s orientation, use “Image Orientation” for the key.