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

master
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
1 changed files with 6 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import copy import copy
import io
import PIL.ExifTags import PIL.ExifTags
import PIL.Image import PIL.Image
@ -111,6 +112,11 @@ def rotate_by_exif(image):
except KeyError: except KeyError:
return (image, exif) 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) exif = copy.deepcopy(exif)
if rotation == 1: if rotation == 1: