Resize image in Python without losing EXIF data

后端 未结 11 2026
野的像风
野的像风 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:19

    For pyexiv2 v0.3.2, the API documentation refers to the copy method to carry over EXIF data from one image to another. In this case it would be the EXIF data of the original image over to the resized image.

    Going off @Maksym Kozlenko, the updated code for copying EXIF data is:

        source_image = pyexiv2.ImageMetadata(source_path)
        source_image.read()
    
        dest_image = pyexiv2.ImageMetadata(dest_path)
        dest_image.read()
    
        source_image.copy(dest_image,exif=True)
        dest_image.write()
    

提交回复
热议问题