Programming Digital Media

Extracting JPEG headers

Extracting JPEG headers Gene Cash has written a Python module that will read the header data in the image files produced by digital cameras. I have written a short program to test the extraction of the timestamp from the image file headers.
  1. First, take a look at his description of the EXIF header.
  2. Then, download his EXIF Python module.
  3. Also download my short test script, jpeg_time.py. Put it and the EXIF.py module in the same directory, and run your tests from there.
  4. See if you've installed things correctly by running my script without arguments:
    python jpeg_time.py 
    
    It should print out this:
     
    Usage: python jpeg_time.py <jpeg-filenames> 
     
    Print the time information in the header of the listed JPEG files. 
     
    Example: 
     
        python jpeg_time.py /Users/ack/Pictures/*.jpg 
     
    

  5. Run the script on a directory with JPEG pictures from a camera. For example, to run the script on all the files that match *.jpg in the Pictures directory in my home directory, I would enter:
    python jpeg_time.py /Users/ack/Pictures/*.jpg 
    
To sort files by the header timestamp, first make a dictionary of all the filenames and timestamps, and use them in the sorting function so that you do not need to read the JPEG file more than once. The timestamp lists the year first, followed by the month, date and time all in numeric format, so the dates do not need to be reformatted to be sorted. [More on this soon.]