pexif 0.1 release

Fri, 27 Jan 2006 18:46:27 +0000
tech pexif python

Short version: I release some code. It edits EXIF data.

Long version: All I wanted to do was write some simple code to add a GPS location take to my photos. It should have been easy. A couple of hours of scripting at the most. But it wasn't.

Most JPEG images have some meta data at the front of them telling you stuff like, when it was taken, what camera took it, wether the flash was used, and so on, and so on. The latest version of the spec also has a bunch of fields for storing GPS information. Unfortunately my cheapo camera doesn't store that kind of information, so I want to add it in after the fact. I thought I could just grab an existing EXIF editing library and away I would go.

Unfortunately the two Python libraries out there pyexif and EXIF.py, only handle the parsing of EXIF data, not the updating of it. The also seemed to be a C library libexif that claimed to do editing, but it was basically undocumented, I couldn't work out how to use it, and besides I wanted to write in python not C. (And I didn't feel like writing a Python wrapper for a library I didn't uderstand.)

This led me to writing some of my own Python code to try and just do enough to insert the GPS tags and nothing else. Unfortunately the way EXIF works things aren't quite that easy. Inside the file format you end up with internal offset pointers, which means if you change the layout (by inserting some extra tags), you end up needing to change all these pointers to work with the new offsets.

I thought this wouldn't be too bad because I'd just append to the end of the section I was working with, (which was unfortuantely first), and then the other sections could move freely. Unfortuantely these pointers don't reference from the start of a section, they reference from the start of the file. This basically means that I need to parse everything into memory, and then know how to write it all back out again. Pain, pain, pain. (This was of course a bit of a simplication, so please don't email me saying that isn't exactly how EXIF is structured.)

Anyway, I now have a library, which can read all the EXIF data, including the thumbnail section, edit and insert values into it, and then spit out a valid file again. Now I can start writing the code to do the actual tagging, which should be more interesting than this stuff, but right now, time for the LCA dinner.

blog comments powered by Disqus