Resize image in Python without losing EXIF data

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

    Here's an updated answer as of 2018. piexif is a pure python library that for me installed easily via pip (pip install piexif) and worked beautifully (thank you, maintainers!). https://pypi.org/project/piexif/

    The usage is very simple, a single line will replicate the accepted answer and copy all EXIF tags from the original image to the resized image:

    import piexif
    piexif.transplant("foo.jpg", "foo-resized.jpg")
    

    I haven't tried yet, but it looks like you could also perform modifcations easily by using the load, dump, and insert functions as described in the linked documentation.

提交回复
热议问题