Friday, August 17, 2007

EXIF to auto-locate pictures

We allow travelers to upload their personal pictures to replace the stock photos we provide. The traveler will want to add a caption and description then assign the picture to a specific day of the tour. The EXIF information embedded by most modern digital cameras into each picture really helps. By knowing the date/time the picture was taken, we can auto-assign it for the traveler.

Here's how to do it with RMagick:


image = Magick::Image.read('/users/jimjames99/desktop/cat.jpg').first

=> /users/jimjames99/desktop/cat.jpg JPEG 500x295 500x295+0+0 DirectClass 8-bit 132kb

>> image.get_exif_by_entry('DateTime')

=> [["DateTime", "2007:07:31 14:18:15"]]


If there is no date/time encoded into the picture you get this result:


=> [["DateTime", ""]]


There are lots of other EXIF entries that you can query, including make and model of the camera, picture settings, and so on. The specification is here (pdf).

A couple of factors conspire to frustrate this user helper. iPhoto and other picture gallery programs tend to either wipe the EXIF data from pictures or removes it when you export the pictures to upload to another system (like the travel portal). And of course just because the traveler took the picture in Rome doesn't mean that they want to show it on the Rome page. So we have to provide a robust picture assignment functionality. More on that another time.

No comments: