Exif data extraction

Exif extraction module is provided with the library. As many applications often need to access exif data to the same file one by one, there is a cache layer built on top of the raw exif parser. It is implemented as the mg.utils.exif.cache.exif_cache object. The only exported function in this object is get(obj, fd).

exif_cache.get(obj, fd)

Retrieves exif data contained in file descriptor fd, with a cache key determined by the django database object obj.

Parameters:
  • obj – A django database object
  • fd – An open file descriptor (an object with a read() method).
Returns:

An exif object, with a dict-like protocol, None if exif information is not available in the file.

Example:

>>> from mg.utils.exif.cache import exif_cache
>>> from mg.media.photo.models import Photo
>>> photo = Photo.objects.all()[0]
>>> data = exif_cache.get(photo, photo.file.file)
>>> data['EXIF DateTimeOriginal'].values
'2010:12:31 19:41:42'
>>>