Buffer the exif in a bytesio to save from fp being closed.

This commit is contained in:
voussoir 2022-05-07 10:31:31 -07:00
parent 7f2360d1c0
commit 2c8081505a
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -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: