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).




By Gregory Dudek at | Read (8) or Leave a comment |    
Rate item 154: Rating: 7.7/10 (3 votes 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
3.x version?

Is there a 3.x version of this module available? I'm running Python 3.1.2 and importing this module produces a syntax error on line 1182:

>>> import EXIF
Traceback (most recent call last):
File "", line 1, in
import EXIF
File "C:\Python31\lib\EXIF.py", line 1182
y = 0L
^
SyntaxError: invalid syntax

Does anyone know if a 3.1.2 version of an EXIF reader?

[ I think you can just look for integers of the form 0L or 42L and replaced them with 0 and 42. --gd ]

Posted by: seelk at May 12,2010 15:05
3.x version?

I also ran the 2to3 utility included in Python but the EXIF.py file fails to find EXIF information on the JPG files from a Canon SD1000 camera. Ideas?

[ I just tried the EXIF.py code on an image from an SD1000 and it seems to work fine, Perhaps the problem is with 2to3 or some specific tag it's looking for? It may also be something more obscure. --gd ]

Posted by: seelk at May 12,2010 15:23
Re: EXIF.py and Zope Photo product fixes for iPhoto 08 (and 09)

Seelk, can you post a link to one of the problem images? I don't promise to have to to address it, but I'll have a look if I can find time.

Posted by: dudek at June 07,2010 10:29
Version number update?

Gregory, thanks for keeping this product alive.

I found your updated EXIF.py after running into trouble with some Olympus data that Photo 1.2.3 could not handle.

You might want to change the version number: control panel still shows Photo (Installed product Photo (Photo 1.3.2)) .

I made a small modification by adding these lines to manage_addPhotoFolder (line 493):

# Try to acquire display sizes from the parent
ob = self._getOb(id)
if hasattr(ob.aq_parent, '_displays'):
ob._displays = ob.aq_parent._displays.copy()

Rather than using the default display sizes, a child folder will try to acquire those from its parent.

norbert at infocatch dot com

PS is this a Bitakora blog?

[ Thanks. That's the version of the Photo Product, of course. On my Zope, it says it's version 3.2 Perhaps your system is caching the version number somehow.

Incidentally, this blog is run using a somewhat modified version of the COREBlog product for Zope. --gd]

Posted by: infoCatch at June 10,2010 21:13
Re: EXIF.py and Zope Photo product fixes for iPhoto 08 (and 09)

Just a quick thanks - this worked great for me when my Olympus FE2050 camera produced pictures that the old version of EXIF.py couldn't decode.

Posted by: anonymous at June 20,2010 22:47
Re: EXIF.py and Zope Photo product fixes for iPhoto 08 (and 09)

Thank you for this patch, it's a big improvement!

I know it's been a long time (I took a break from Python for a while), but your patch set has been merged into the project.

If you'd like to take a look, development has moved to Github:
https://github.com/ianare/exif-py

Cheers

[ Thanks for letting me know. I very much appreciate your creation of this very nice module and renewed support. -gd ]

Posted by: ianaré at November 29,2012 19:30
Trackbacks
Please send trackback to:/blog/154/tbping
There are no trackbacks.
Post your own response

Each comment is manually screened for the presence of appropriate and substantive content, due to a constant onslaught of comment-spam. This means there may be a delay before your comment appears.


(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.

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



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. They appear after moderation. Don't forget to also fill in the captcha below or your text will be rejected automatically!

You must answer this question to prove you are human
which has the least friendly public image: 1:collie, 2:beagle, 3:doberman, 4:dachsund, 5:dalmatian?

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