mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-31 02:09:58 +03:00
send_file now pads too small images
This commit is contained in:
parent
42cc9e61fb
commit
d1dbd74070
|
@ -15,6 +15,7 @@ from ..tl import types, functions, custom
|
||||||
try:
|
try:
|
||||||
import PIL
|
import PIL
|
||||||
import PIL.Image
|
import PIL.Image
|
||||||
|
import PIL.ImageOps
|
||||||
except ImportError:
|
except ImportError:
|
||||||
PIL = None
|
PIL = None
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ class _CacheType:
|
||||||
|
|
||||||
|
|
||||||
def _resize_photo_if_needed(
|
def _resize_photo_if_needed(
|
||||||
file, is_image, width=1280, height=1280, background=(255, 255, 255)):
|
file, is_image, min_width=40, min_height=40, width=1280, height=1280, background=(255, 255, 255)):
|
||||||
|
|
||||||
# https://github.com/telegramdesktop/tdesktop/blob/12905f0dcb9d513378e7db11989455a1b764ef75/Telegram/SourceFiles/boxes/photo_crop_box.cpp#L254
|
# https://github.com/telegramdesktop/tdesktop/blob/12905f0dcb9d513378e7db11989455a1b764ef75/Telegram/SourceFiles/boxes/photo_crop_box.cpp#L254
|
||||||
if (not is_image
|
if (not is_image
|
||||||
|
@ -58,10 +59,14 @@ def _resize_photo_if_needed(
|
||||||
except KeyError:
|
except KeyError:
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
|
||||||
if image.width <= width and image.height <= height:
|
too_small = image.width < min_width or image.height < min_height
|
||||||
return file
|
if too_small:
|
||||||
|
image = PIL.ImageOps.pad(image, (max(image.width, min_width), max(image.height, min_height)), color=(255, 255, 255))
|
||||||
|
else:
|
||||||
|
if (image.width <= width and image.height <= height):
|
||||||
|
return file
|
||||||
|
|
||||||
image.thumbnail((width, height), PIL.Image.ANTIALIAS)
|
image.thumbnail((width, height), PIL.Image.ANTIALIAS)
|
||||||
|
|
||||||
alpha_index = image.mode.find('A')
|
alpha_index = image.mode.find('A')
|
||||||
if alpha_index == -1:
|
if alpha_index == -1:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user