Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify EXIF data in python

Tags:

I am trying to edit/modify existing metadata within python 2.7. More specifically I have GPS coordinates in a my metedata, however the altitude field is incorrect. Is there a way of changing this?

I have had a look at PIL piexif pyexif, but I cannot seem to find a way to modify existing fields.

Has anyone managed to do this? It sounds like it would be very simple, but I can't seem to work it out.

like image 825
D.Griffiths Avatar asked Jun 19 '17 17:06

D.Griffiths


People also ask

Can you modify EXIF data?

Select the picture you want to edit EXIF data for. To view EXIF data, you can tap the various icons below the image. To edit or remove EXIF data (after you pay for the app), tap Metadata. Now select Remove or Edit.

Can we add our own Exif parameter?

EXIF key-value pairs are called tags, and each tag can contain either a string or numeric value. There are dozens of tags in the current EXIF standard (version 2.32), and anyone — from smartphone and camera manufacturers to photographers — is free to add their own.


1 Answers

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) 
like image 174
Franz Forstmayr Avatar answered Sep 22 '22 09:09

Franz Forstmayr