I am trying to strip out exif data on an uploaded image before continuing to do some other processing to it before saving to the server.
I am using piexif as in this answer to strip out the exif metadata. However, piexif.insert() documentation requires the path to the image being modified. Can piexif be used to write to a file in memory?
PIL is also documented to strip out exif data. Since I am using PIL anyways, I'd rather have a pure PIL approach.
def modifyAndSaveImage():
# Get the uploaded image as an InMemoryUploadedFile
i = form.cleaned_data['image']
# Use piexif to remove exif in-memory?
#exif_bytes = piexif.dump({})
#piexif.insert(exif_bytes, i._name) # What should the second parameter be?
# continue using i...
im = Image.open(i)
buffer = BytesIO()
im.save(fp=buffer, format='JPEG', quality=95)
return ContentFile(buffer.getvalue())
PIL's save method seems to be applying the exif data to the image, than saving it without the exif (applies rotation to the raw image). Or is this caused by the BytesIO buffer?