From 06545d18119eaba88404b9709f94f54b405de561 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Fri, 12 May 2023 16:42:12 +0300 Subject: [PATCH] fix sticker resize --- bots/modules/stickers.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bots/modules/stickers.py b/bots/modules/stickers.py index 8728fc3..cf79bc0 100644 --- a/bots/modules/stickers.py +++ b/bots/modules/stickers.py @@ -29,8 +29,15 @@ class StickersBotModuleConfig(TelegramBotModuleConfig): f.seek(0) im = Image.open(f).convert('RGBA') width, height = im.size - im.thumbnail((512, 512), Image.ANTIALIAS) - target_width, target_height = im.size + long_dimension = max(width, height) + scale_ratio = 512 / long_dimension + target_width = int(width * scale_ratio) + target_height = int(height * scale_ratio) + if long_dimension == width: + target_width = 512 + else: + target_height = 512 + im.resize((target_width, target_height), Image.ANTIALIAS) with tempfile.NamedTemporaryFile(suffix='.png') as f: im.save(f, 'png') f.seek(0)