Skip to content

Instantly share code, notes, and snippets.

@fyr91
Created November 6, 2013 07:16
Show Gist options
  • Save fyr91/7332203 to your computer and use it in GitHub Desktop.
Save fyr91/7332203 to your computer and use it in GitHub Desktop.
Locate photo with GPSInfo in. Just a test. Based on Erans' work get_lat_lon_exif_pil.py.
from PIL import Image, ExifTags
import webbrowser
def converter(value):
d0 = value[0][0]
d1 = value[0][1]
d = float(d0) / float(d1)
m0 = value[1][0]
m1 = value[1][1]
m = float(m0) / float(m1)
s0 = value[2][0]
s1 = value[2][1]
s = float(s0) / float(s1)
return d + (m / 60.0) + (s / 3600.0)
def inList(a, b):
for item in a:
if item not in b.keys():
return False
else:
return True
img = Image.open('fileName')
exif = {
ExifTags.TAGS[k]: v
for k, v in img._getexif().items()
if k in ExifTags.TAGS
}
GPS = {}
if 'GPSInfo' in exif.keys():
for key in exif['GPSInfo'].keys():
decode = ExifTags.GPSTAGS.get(key,key)
GPS[decode] = exif['GPSInfo'][key]
ls = ['GPSLongitude','GPSLatitude','GPSLongidudeRef','GPSLatitudeRef']
if inList(ls, GPS):
lat = converter(GPS['GPSLatitude'])
if GPS['GPSLatitudeRef'] != "N":
lat = 0 - lat
lon = converter(GPS['GPSLongitude'])
if GPS['GPSLongitudeRef'] != "E":
lon = 0 - lon
url = "https://www.google.com.sg/maps/preview#!q="+str(lat)+"%2C"+str(lon)
webbrowser.open_new_tab(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment