Last active
April 26, 2017 11:18
-
-
Save iRGBit/8e0d5d65984abbe585697f776385374f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://gist.github.com/valgur/2fbed04680864fab1bfc | |
import PIL.Image | |
import pprint | |
get_float = lambda x: float(x[0]) / float(x[1]) | |
def convert_to_degrees(value): | |
d = get_float(value[0]) | |
m = get_float(value[1]) | |
s = get_float(value[2]) | |
return d + (m / 60.0) + (s / 3600.0) | |
def get_lat_lon(info): | |
try: | |
gps_latitude = info[34853][2] | |
gps_latitude_ref = info[34853][1] | |
gps_longitude = info[34853][4] | |
gps_longitude_ref = info[34853][3] | |
lat = convert_to_degrees(gps_latitude) | |
if gps_latitude_ref != "N": | |
lat *= -1 | |
lon = convert_to_degrees(gps_longitude) | |
if gps_longitude_ref != "E": | |
lon *= -1 | |
return lat, lon | |
except KeyError: | |
return None | |
if __name__ == '__main__': | |
image = PIL.Image.open('images/IMG_2478.JPG') | |
info = image._getexif() | |
print get_lat_lon(info) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment