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)