Added saving of exif image data when resizing it using pillow. This allows you load images with proper orientation. Not only landscape but also portrait.

This commit is contained in:
strannik-j 2020-12-29 23:42:34 +03:00
parent acd4c8648e
commit cc9537bb78

View File

@ -53,6 +53,7 @@ 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']
if image.width <= width and image.height <= height:
return file
@ -72,7 +73,7 @@ def _resize_photo_if_needed(
result.paste(image, mask=image.split()[alpha_index])
buffer = io.BytesIO()
result.save(buffer, 'JPEG')
result.save(buffer, 'JPEG', exif=exif)
buffer.seek(0)
return buffer