views:

4815

answers:

6

I'm looking for good exif (Exchangeable image file format) manipulation library for python. I prefer flexibility (e.g., ability to retrieve providers' proprietary tags) than processing speed. What would you suggest?

+10  A: 

You might want to check out EXIF-py:

Python library to extract EXIF data from tiff and jpeg files. Very easy to use - $ ./EXIF.py image.jpg

or the Python Imaging Library (PIL):

The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities.

There's also the aptly named pyexif: http://pyexif.sourceforge.net/

The pyexif python library and tools aims at extracting EXIF information from Jpeg and Tiff files which include it. This information is typically included in images created using digital imaging devices such as digital cameras, digital film scanners, etc.

However, it looks like pyexif hasn't been updated in quite while. They recommend if theirs isn't doing the trick to check out EXIF-py, so you should probably try that one first, as their sourceforge page seems to have some activity there lately, though not much. Finally, using PIL you could do this:

from PIL import Image
from PIL.ExifTags import TAGS

def get_exif(fn):
    ret = {}
    i = Image.open(fn)
    info = i._getexif()
    for tag, value in info.items():
        decoded = TAGS.get(tag, tag)
        ret[decoded] = value
    return ret

Disclaimer:
I actually have no idea which is best, this is just what I was able to piece together with Google. :)

Paolo Bergantino
+6  A: 

I've been using pyexiv2 myself recently, and it seems to fit my needs quite nicely. Perhaps it might suit yours as well.

Lars Wirzenius
For the record: pyexiv2 seems to be the best-maintained of them all, and the most complete (including writing EXIF tags back to the file).
rbp
+3  A: 

You might also look at Gheorghe Milas' jpeg.py library at http://www.emilas.com/jpeg/, which is "A python library to parse, read and write JPEG EXIF, IPTC and COM metadata."

A drawback is that he appears to be hosting his domain on a dynamic IP via DynDNS, so it's not always available.

A: 

There are some examples of PIL and EXIF.py usage on ASPN

Michał Niklas
+3  A: 

This article describes a Python module for writing EXIF metadata (and not just reading them) using pure Python. Apparently, none of PIL, pyexif, nor EXIF-py support writing EXIF. pyexiv2 appears to be bleeding-edge and platform-specific.

Jason R. Coombs
A: 

In Python 2.6 the place of module is different. Use this:

import Image    
from ExifTags import TAGS
Tomasz Nazar