Last active
May 18, 2022 20:11
-
-
Save ifahadone/988faa7b1bedc4d2daa540586bad78fb to your computer and use it in GitHub Desktop.
get longitude and latitude from image URL using python.
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
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