Python: Remove Exif info from images

后端 未结 4 1872
天命终不由人
天命终不由人 2020-11-30 06:02

In order to reduce the size of images to be used in a website, I reduced the quality to 80-85%. This decreases the image size quite a bit, up to an extent.

To reduce

相关标签:
4条回答
  • 2020-11-30 06:32

    For me, gexiv2 works fine:

    #!/usr/bin/python3
    
    from gi.repository import GExiv2
    
    exif = GExiv2.Metadata('8snmhp4sjd75vdr27gbadolc003i.jpg')
    exif.clear_exif()
    exif.clear_xmp()
    exif.save_file()
    

    See also Exif manipulation library for python, which you linked, but didn't read all answers ;)

    0 讨论(0)
  • 2020-11-30 06:38

    You can try loading the image with the Python Image Lirbary (PIL) and then save it again to a different file. That should remove the meta data.

    0 讨论(0)
  • 2020-11-30 06:39
    from PIL import Image
    
    image = Image.open('image_file.jpeg')
    
    # next 3 lines strip exif
    data = list(image.getdata())
    image_without_exif = Image.new(image.mode, image.size)
    image_without_exif.putdata(data)
    
    image_without_exif.save('image_file_without_exif.jpeg')
    
    0 讨论(0)
  • 2020-11-30 06:52

    You don't even need to do the extra steps @user2141737 suggested. Just opening it up with PIL and saving it again seems to do the trick just fine:

    from PIL import Image
    image = Image.open('path/to/image')
    image.save('new/path/' + file_name)
    
    0 讨论(0)
提交回复
热议问题