Skip to content

Instantly share code, notes, and snippets.

@Ripley6811
Created April 1, 2013 08:13
Show Gist options
  • Save Ripley6811/5283781 to your computer and use it in GitHub Desktop.
Save Ripley6811/5283781 to your computer and use it in GitHub Desktop.
ccess EXIF data of images. Preserve EXIF data after PIL manipulation of an image. Requires exiftool.exe. Download from http://www.sno.phy.queensu.ca/~phil/exiftool/
'''
Preserve EXIF data after PIL manipulation of an image.
Requires exiftool.exe. Download from http://www.sno.phy.queensu.ca/~phil/exiftool/
Basically, do not save the manipulated image over the old image. Exiftool can
copy the data from old to new.
'''
from PIL import Image
import subprocess
exiftool = r'C:\...\exiftool.exe' # Path to exiftool.exe program
filename = r'C:\...\image.jpg' # Path to original image
savename = r'C:\...\image_new.jpg' # Destination for manipulated image
image = Image.open( filename )
...# Manipulate image data
# Save image and copy EXIF from old to new
image.save( savename )
subprocess.call([exiftool,
savename,
'-tagsFromFile',
filename], shell=True)
# Delete or rename old image as a backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment