Resize image in Python without losing EXIF data

There is actually a really simple way of copying EXIF data from a picture to another with only PIL. Though it doesn’t permit to modify the exif tags.

image = Image.open('test.jpg')
exif = image.info['exif']
# Your picture process here
image = image.rotate(90)
image.save('test_rotated.jpg', 'JPEG', exif=exif)

As you can see, the save function can take the exif argument which permits to copy the raw exif data in the new image when saving. You don’t actually need any other lib if that’s all you want to do. I can’t seem to find any documentation on the save options and I don’t even know if that’s specific to Pillow or working with PIL too. (If someone has some kind of link, I would enjoy if they posted it in the comments)

Leave a Comment