Resize image in Python without losing EXIF data

后端 未结 11 2076
野的像风
野的像风 2020-12-02 19:06

I need to resize jpg images with Python without losing the original image\'s EXIF data (metadata about date taken, camera model etc.). All google searches about python and i

11条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 19:17

    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)

提交回复
热议问题