Preserve exif data of image with PIL when resize(create thumbnail)

后端 未结 3 1662
迷失自我
迷失自我 2020-11-30 11:15

When I try to resize (thumbnail) an image using PIL, the exif data is lost.

What do I have to do preserve exif data in the thumbnail image? When I searched for the s

3条回答
  •  北海茫月
    2020-11-30 11:38

    import pyexiv2
    from PIL import  Image
    
    file_path = '/home/../img/a.JPG'
    metadata = pyexiv2.ImageMetadata(file_path)
    metadata.read()
    thumb = metadata.exif_thumbnail
    thumb.set_from_file(file_path)
    thumb.write_to_file('512_' + "a")
    thumb.erase()
    metadata.write()
    

    Now I open the image using (Patch Image Inspector) , I can see the exif data

提交回复
热议问题