1
12 March
2009

A fix to EXIF.py to make it find the data more consistently

The Python EXIF.py module is for extracting tags from an image. If the image has been edited with Apple's iPhoto 08 (or probably iPhoto 09 or other software) though, EXIF.py may be unable to find the EXIF tags and you might get a message like "No EXIF information found." Some people have suggested that iPhoto is stripping the EXIF data. In fact, the issue is that EXIF.py does not like it if there is other information before the EXIF segment in the file (specifically something called an APP2 segment). In short, EXIF.py only handles a subset of possible JPEG file formats. This was a particular problem for me since I use EXIF.py on my Zope web site (this one) with the Photo product to display information.

I found the problem and fixed it and also updated the Photo product as well. The modified version of EXIF.py that is able to parse these files can be found at the following link [EXIF.py]. I've also posted the fix to the maintainers, but don't know how soon they might accept it.

The basis of the problem relates to the flexibility of the JPEG/EXIF file format. A JPEG file is composed of several segments including the image, a thumbnail, and parts called APP1 and APP2. The standard EXIF.py module expected APP1 to be the first segment in the file, and didn't work if APP2 came before APP1, but this is how iPhoto creates JPEG files. The new version I have posted is smarter about interpreting the segments (although the actual code is rather ugly).

Download link:
link [EXIF.py].


Usage: python EXIF.py pic.jpg

Or, it can be used inside a python program:

import EXIF
f=open("pic.jpg")
print EXIF.process_file(f)


I have also included a substantially updated version of the wonderful Zope Photo product that was originally created by Rob Bickers (rbickers) and then updated and improved by Søren Roug [ zope.org link].


This version merges changes from the 1.3.2 and 1.2.4 branches, includes this updated EXIF.py, and has some code changes (such as a method called "exifdata" that takes an EXIF field name for display, no field at all, or a special meta-fields such as "Date"). It also includes patches that allow Zope images to be re-created as Photo objects.

You can see the product used here at dudek.org/Recruiting2009 to produce the EXIF summary at the top of the picture (click that for more details). I am calling this version 31 and it's a compressed tar file [ photo31.tgz ]. It is also used to produce the images shown here.




Picture with EXIF dataPicture with EXIF data


{'Image ExifOffset': (0x8769) Long=360 @ 138, 'EXIF CustomRendered': (0xA401) Short=Normal @ 694, 'EXIF MeteringMode': (0x9207) Short=Pattern @ 502, 'EXIF DateTimeOriginal': (0x9003) ASCII=2009:03:11 20:20:29 @ 754, 'MakerNote FirmwareVersion': (0x0007) ASCII=Firmware Version 1.0.7 @ 1490, 'EXIF ExifImageWidth': (0xA002) Short=5616 @ 622, 'EXIF SubSecTimeOriginal': (0x9291) ASCII=74 @ 574, 'Image XResolution': (0x011A) Ratio=72 @ 196, 'Image YResolution': (0x011B) Ratio=72 @ 204, 'EXIF ShutterSpeedValue': (0x9201) Signed Ratio=21/8 @ 794, 'EXIF ISOSpeedRatings': (0x8827) Short=3200 @ 406, 'EXIF ExposureTime': (0x829A) Ratio=1/6 @ 738, 'MakerNote ImageType': (0x0006) ASCII=Canon EOS 5D Mark II @ 1458, 'MakerNote Tag 0x00AA': (0x00AA) Short=[12L, 1124L, 1024L, 1024L, 715L, 1L] @ 5300, 'Image YCbCrPositioning': (0x0213) Short=Co-sited @ 114, 'Thumbnail XResolution': (0x011A) Ratio=72 @ 10532, 'EXIF ExposureProgram': (0x8822) Short=Program Normal @ 394, 'Image GPSInfo': (0x8825) Long=8660 @ 150, 'Image Copyright': (0x8298) ASCII=Copyright: Gregory Dudek @ 296,






Picture with EXIF data





Please let me know if you have any difficulties with or (or not).




Posted by dudek at 22:09 March 12, 2009 | Read (2) or Leave a comment | permalink link to this entry |
Rate item 154: Rating: 10.0/10 (1 vote cast)
Comments
Re: EXIF.py and Zope Photo product fixes for iPhoto 08 (and 09)

I've been looking around for a python library to manipulate EXIF tags (in a read-only fashion). I'm still in the very early stages of looking, so I haven't tried using any yet, but on searching, I've been dismayed to find that there isn't a single mature "proper" library for the job.

"exif.py" comes up a lot, though. Your post exposing the implementation as it does leaves me in even more despair: this "common denominator" library is clearly crap too!

I might detour from my quest for a decent library (well, truthfully for my purposes I'll probably use PIL) to assemble a decent JPEG/EXIF test suite, although I doubt *any* implementation will hold up to such a thing...

Posted by: Jon at January 31,2010 17:09
Don't despair

While EXIF has been around a while, it is only recently really getting used a lot. Don't despair, these growing pains are not so bad and EXIF.py is really quite pleasant to use.

Posted by: dudek at February 03,2010 22:44
Trackbacks
Please send trackback to:/blog/154/tbping
There are no trackbacks.
Post your own response


(Some kind of name is required, will be visible)

Required, whatever you enter will be visible to other users.


(Optional, used for "mailto" link)

Your email address is not required, but if you insert it it will be displayed so people can contact you.


(Optional, will appear as a link)

Leave an URL if you want to provide a relevant link that relates to your comment or identifies you.



The title for your comment.



Your comment goes here. All relevant comments are welcome, except for those that simply promote an irrelevant product or else are used to fraudulently inflate the link count to an irrelevant web page. Don't forget to also fill in the captcha below or your text will be rejected!

You must answer this question to prove you are human
what is 3 plus 4?

Answer this question correctly to demonstrate that you are not a dumb spambot.







Science Blogs - Blog Top Sites Science Blogs - Blog Catalog Blog Directory Science Blogs - Blog Top Sites Science Blogs - Blog Catalog Blog Directory