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.
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. :)
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.
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.
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).
somehow i get an attributeError for _getexif with Paolo's code above.. I am using Python 2.6.6 and PIL 1.1.7. Is _getexif obsolete now??
Here's a small modification that worked for me.
from PIL import Image
from PIL.ExifTags import TAGS
def get_exif(fn):
ret = {}
i = Image.open(fn)
# info = i._getexif()
info = i.tag.tags
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
return ret
I have been using my own wrappers around http://www.sno.phy.queensu.ca/~phil/exiftool/
-- the reason is that it is very complete, the dev is very active. And not being able to support almost all image formats is a absolute showstopper for the project it is needed for
The drawback of course is that it isn't python, so you would need to use subprocess calls, as I do.