Skip to content

Instantly share code, notes, and snippets.

@ifahadone
Last active May 18, 2022 20:11
Show Gist options
  • Save ifahadone/988faa7b1bedc4d2daa540586bad78fb to your computer and use it in GitHub Desktop.
Save ifahadone/988faa7b1bedc4d2daa540586bad78fb to your computer and use it in GitHub Desktop.
get longitude and latitude from image URL using python.
from io import BytesIO
import requests
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
def get_long_lati(img_url:str):
response = requests.get(img_url)
img = Image.open(BytesIO(response.content))
exif = img.getexif()
img.close()
if exif is None or not exif:
return None
else:
global key
for key, value in TAGS.items():
if value == "GPSInfo":
break
gps_info = exif.get_ifd(key)
return {
GPSTAGS.get(key, key): value
for key, value in gps_info.items()
}
print(get_long_lati("http://URL.here"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment