Skip to content

Instantly share code, notes, and snippets.

@sinebeef
Created May 29, 2020 10:19
Show Gist options
  • Save sinebeef/b6976896dee11b79ccc25b3ac2a328e9 to your computer and use it in GitHub Desktop.
Save sinebeef/b6976896dee11b79ccc25b3ac2a328e9 to your computer and use it in GitHub Desktop.
GPS / Geo tag JPEG images using python and exiftool on the command line
# exiftool file.jpg {views file}
# exiftool -Make="Canon"
# exiftool -Model="Canon EOS 40D"
import random
from geopy.geocoders import Nominatim
from GPSPhoto import gpsphoto
import sys, os
geolocator = Nominatim(user_agent="geodata")
location = geolocator.geocode("Chelmsford, Essex")
print(location)
lat = location.latitude
lon = location.longitude
latseed = round(random.uniform(-0.0036143,0.0036143),7)
lonseed = round(random.uniform(-0.0072286,0.0072286),7)
#print(round(lat + latseed,7), round(lon + lonseed,7))
pictures = os.listdir()
for picture in pictures:
if picture.endswith('.jpg'):
photo = gpsphoto.GPSPhoto(picture)
info = gpsphoto.GPSInfo((round(lat + latseed,7), round(lon + lonseed,7)))
photo.modGPSData(info, picture)
# https://stackoverflow.com/questions/53543549/change-exif-data-on-jpeg-without-altering-picture
# exif_dict = piexif.load(path)
# new_exif = adjust_exif(exif_dict)
# exif_bytes = piexif.dump(new_exif)
# piexif.insert(exif_bytes, path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment