From 2c8081505ae2c057ffaeb18ef2014d80720c19c3 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 7 May 2022 10:31:31 -0700 Subject: [PATCH] Buffer the exif in a bytesio to save from fp being closed. --- voussoirkit/imagetools.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/voussoirkit/imagetools.py b/voussoirkit/imagetools.py index 58b9aad..f941d40 100644 --- a/voussoirkit/imagetools.py +++ b/voussoirkit/imagetools.py @@ -1,4 +1,5 @@ import copy +import io import PIL.ExifTags import PIL.Image @@ -111,6 +112,11 @@ def rotate_by_exif(image): except KeyError: return (image, exif) + fp = getattr(exif, 'fp', None) + if isinstance(fp, io.BufferedReader): + exif.fp = io.BytesIO() + exif.fp.write(fp.read()) + exif.fp.seek(0) exif = copy.deepcopy(exif) if rotation == 1: