How to modify EXIF data in python
import piexif
from PIL import Image
img = Image.open(fname)
exif_dict = piexif.load(img.info['exif'])
altitude = exif_dict['GPS'][piexif.GPSIFD.GPSAltitude]
print(altitude)
(550, 1) % some values are saved in a fractional format. This means 550m, (51, 2) would be 25,5m.
exif_dict['GPS'][piexif.GPSIFD.GPSAltitude] = (140, 1)
This sets the altitude to 140m
exif_bytes = piexif.dump(exif_dict)
img.save('_%s' % fname, "jpeg", exif=exif_bytes)
Late answer, but you can use GPSPhoto, i.e.:
from GPSPhoto import gpsphoto
photo = gpsphoto.GPSPhoto("photo.jpg")
# Create GPSInfo Data Object
# info = gpsphoto.GPSInfo((38.71615498471598, -9.148730635643007))
# info = gpsphoto.GPSInfo((38.71615498471598, -9.148730635643007), timeStamp='2018:12:25 01:59:05')'''
info = gpsphoto.GPSInfo((38.71615498471598, -9.148730635643007), alt=83, timeStamp='2018:12:25 01:59:05')
# Modify GPS Data
photo.modGPSData(info, 'new_photo.jpg')
Installation:
pip install GPSPhoto