1

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?

Community
  • 1
  • 1
Dirty Penguin
  • 4,212
  • 9
  • 45
  • 69

1 Answers1

1

Since the primary constraint seems to be "something that runs on my tiny VPS", consider installing and using exiftool for this task, and make a system call to it:

exiftool -all= -overwrite_original tmp.jpg

This doesn't exactly answer your question about using python streams, but may solve your problem.

Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49
  • Thanks Mark. That worked perfectly. The memory usage didn't jump and the exif was stripped. I'd still like to know if it's possible to use PIL with chunking, so I'm going to keep the question open. – Dirty Penguin Jan 17 '16 at 18:38