fix sticker resize
This commit is contained in:
parent
6d74a7fffe
commit
06545d1811
@ -29,8 +29,15 @@ class StickersBotModuleConfig(TelegramBotModuleConfig):
|
|||||||
f.seek(0)
|
f.seek(0)
|
||||||
im = Image.open(f).convert('RGBA')
|
im = Image.open(f).convert('RGBA')
|
||||||
width, height = im.size
|
width, height = im.size
|
||||||
im.thumbnail((512, 512), Image.ANTIALIAS)
|
long_dimension = max(width, height)
|
||||||
target_width, target_height = im.size
|
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:
|
with tempfile.NamedTemporaryFile(suffix='.png') as f:
|
||||||
im.save(f, 'png')
|
im.save(f, 'png')
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user