mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-30 17:59:55 +03:00
Fix KeyError. It works with pillow => 2.0.0.
This commit is contained in:
parent
cc9537bb78
commit
ea0c4367f0
|
@ -53,7 +53,11 @@ def _resize_photo_if_needed(
|
|||
# Don't use a `with` block for `image`, or `file` would be closed.
|
||||
# See https://github.com/LonamiWebs/Telethon/issues/1121 for more.
|
||||
image = PIL.Image.open(file)
|
||||
exif = image.info['exif']
|
||||
try:
|
||||
exif = image.info['exif']
|
||||
except KeyError:
|
||||
exif = None
|
||||
|
||||
if image.width <= width and image.height <= height:
|
||||
return file
|
||||
|
||||
|
@ -73,7 +77,10 @@ def _resize_photo_if_needed(
|
|||
result.paste(image, mask=image.split()[alpha_index])
|
||||
|
||||
buffer = io.BytesIO()
|
||||
result.save(buffer, 'JPEG', exif=exif)
|
||||
if exif:
|
||||
result.save(buffer, 'JPEG', exif=exif)
|
||||
else:
|
||||
result.save(buffer, 'JPEG')
|
||||
buffer.seek(0)
|
||||
return buffer
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user