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:

10 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!

  5. Got it to work, i dont know what was i doing.
    sleep speaks so loud when we dont go to bed like normal people…
    get it to work
    now im only trying to make it like the coords of a regular gps:
    123 deg 12′ 234″ E

    anyone did it already? its just a matter of concat the numbers before the processing i know…

Leave a Reply