Saturday, November 10, 2012

Getting EXIF Data

PIL provides a nice function  to retrieve the EXIF data from an image file. It is a 'hidden' function and it seems to work fairly well. I don't know how well it works with manufacturer specific information however.

To access the EXIF data, simply open an image with PIL:
from PIL import Image

im=Image.open('./someImage')

to get the EXIF data, simply call this function:

exifData=im._getexif()

This will produce a dictionary, exifData, with various numbers as the keys that store some EXIF data value. To help understand what those numbers are, PIL has a list to relate the numbers to words:

from PIL.ExifTags import TAGS

Which if you print the dictionary TAGS, it looks something like this:
4096: 'RelatedImageFileFormat', 513: 'JpegIFOffset', 514: 'JpegIFByteCount', 40963: 'ExifImageHeight', 36868: 'DateTimeDigitized', 37381: 'MaxApertureValue', 37382: 'SubjectDistance', 4097: 'RelatedImageWidth', 37384: 'LightSource', 37385: 'Flash', 37386: 'FocalLength', 37387: 'FlashEnergy', 37388: 'SpatialFrequencyResponse'...

It could then be possible to use the EXIF information to rename your images with something more useful.

No comments:

Post a Comment