The EXIF digital camera file format


Olympus C-3000Z A picture file from a modern digital camera contains more than just the image that the camera took. It can also contain: This meta-information is kept in the "Exchangeable Image File Format for Digital Still Cameras" (EXIF) header. This standard was developed by the Japan Electronic Industry Development Association (JEIDA) and observed by camera industry leaders such as Nikon, Canon, Kodak, Olympus, etc. A much more readable description is at TsuruZoh Tachibanaya's website which also includes MakerNote formats for various makes.

This header is stored in an "application segment" of a JPEG file, or as privately defined tags in a TIFF file. This means that the resulting JPEG or TIFF is still in a standard format readable by applications that are ignorant of EXIF information. Note that most such applications usually don't keep around anything that they don't understand, so if you edit the image, you will lose the EXIF information.

I wrote EXIF.py to extract this data into a Python dictionary suitable for use by image gallery programs and other such applications.
There is only one public function:
process_file(file, debug=0)
where file is an open file like object that supports seek(), and debug is a flag that enables debugging output when true.

It returns a dictionary of EXIF tags found, keyed by tag name, and possibly a thumbnail. The entries are "IFD_Tag" objects.

Object Attributes Meaning
printable String representation of tag, suitable for printing.
tag Numeric tag ID.
field_type Index into the FIELD_TYPES list. Each FIELD_TYPES entry is a (length of type in bytes, type name abbreviation, type full name) tuple.
values String or array of raw values from tag.
field_offset Offset of start of tag from beginning of file. Used by MakerNote processing.

Tag names are prefixed with the name of the IFD, to prevent collisions between tags with the same name in different IFDs.

Example Code
exiftool is a example command-line tool using the above library. It can generate plain-text or HTML files from the EXIF information. It can extract the thumbnail (if any) to a separate file. It can also rename the files according to the EXIF creation date. This was inspired by the utility by Robert F. Tobler <rft@cg.tuwien.ac.at>.