Based on one of the solutions here, I'm using the following code to strip out the EXIF data from an image:
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)
I found this function works just fine on my local machine, however, when I try to run this on my tiny DigitalOcean VPS it causes my gunicorn process to crash.
I'm guessing this is due to img.getdata()
returning something huge.
How might I strip out the EXIF by reading/writing in chunks as opposed to reading the entire image into memory?