Skip to content

Instantly share code, notes, and snippets.

@maxbellec
Forked from erans/get_lat_lon_exif_pil.py
Last active December 5, 2023 12:39
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maxbellec/dbb60d136565e3c4b805931f5aad2c6d to your computer and use it in GitHub Desktop.
Save maxbellec/dbb60d136565e3c4b805931f5aad2c6d to your computer and use it in GitHub Desktop.
Get Latitude and Longitude from EXIF using PIL
import PIL.Image
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
@arpanchal
Copy link

Hi,
what is 'info' in the argument?
Is it gps exif info?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment