Exif manipulation library for python

Python Programming

Question or problem about Python programming:

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?

How to solve the problem:

Solution 1:

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

I actually have no idea which is best, this is just what I was able to piece together with Google. ๐Ÿ™‚

Solution 2:

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

Solution 3:

Exiv2 Based solutions

Exiv2 (exiv2: http://exiv2.org/) is a mature, open-source C++ library that supports reading and writing metadata to many image types (JPEG, PNG, TIFF and many raw formats), understands standard (Xmp, IPTC and Exif) and non-standard metadata (“Makernotes”), and runs on multiple platforms (Windows, Linux, and, with some work, Mac).

Python bindings to exiv2 are:

  • gexiv2 (a multi-language binding, but works with python 2.6/2.7/3.X): https://wiki.gnome.org/gexiv2
  • pyexiv2 (no longer supported, but works with python 2.6/2.7): http://tilloy.net/dev/pyexiv2/

One advantage of pyexiv2 is that there is a windows build available for python 2.7. A windows build request for gexiv2 is here: https://bugzilla.gnome.org/show_bug.cgi?id=712441

exiv2 and the bindings are all open source (GPL).

Solution 4:

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.

Solution 5:

Use PIL ๐Ÿ™‚

import os,sys
from PIL import Image
from PIL.ExifTags import TAGS

if __name__ == '__main__':
    for (k,v) in Image.open(sys.argv[1])._getexif().iteritems():
        print '%s = %s' % (TAGS.get(k), v)

Hope this helps!