Python:使用流从图像中剥离EXIF

时间:2016-01-17 06:20:43

标签: python-2.7 python-imaging-library

根据其中一个解决方案here,我使用以下代码从图片中删除EXIF数据:

def remove_exif_from_image(image_path):
    img = Image.open(image_path)
    data = list(img.getdata())
    clean_img = Image.new(img.mode, img.size)
    clean_img.putdata(data)
    clean_img.save(image_path)

我发现这个功能在我的本地机器上工作得很好,但是,当我尝试在我的小型DigitalOcean VPS it causes my gunicorn process to crash上运行它时。

我猜这是因为img.getdata()返回了一些巨大的东西。

如何通过读取/写入块而不是将整个图像读入内存来剥离EXIF?

1 个答案:

答案 0 :(得分:1)

由于主要约束似乎是“在我的小VPS上运行的东西”,考虑安装并使用exiftool执行此任务,并对其进行系统调用:

exiftool -all= -overwrite_original tmp.jpg

这并不完全回答您关于使用python流的问题,但可能会解决您的问题。