Extract GPS Latitude and Longitude Data from EXIF using Python Imaging Library (PIL)

I was searching an example of using Python Imaging Library (PIL) to extract the GPS data from EXIF data in images.

There were various half baked examples that didn’t handle things well, so I baked something of my own combining multiple examples.

You can get it here: https://gist.github.com/983821

Or see it embedded below:

8 thoughts on “Extract GPS Latitude and Longitude Data from EXIF using Python Imaging Library (PIL)”

  1. Very valuable snippet, thanks! I found two bugs in Your code above:

    Line 7: Missing catch
    Line 11ff: Wrong indentation

  2. Oh sweet! Thanks! I needed that helper function! Why don’t they just use long/lat? or at least have both formats?

  3. @Chris what do you mean? This is the way to convert the values in EXIF, which are in degrees, minutes and seconds to the decimal format.

    What other formats are you talking about?

  4. This is really awesome! Only suggestion is in _convert_to_degrees(), watch out for the divide by zero issue if degrees, minutes, or seconds are 0. Easy enough to fix though.

    Super helpful!

Leave a Reply