From 8290974235182dccab384f8fc5be653987c1b8c5 Mon Sep 17 00:00:00 2001 From: udf Date: Fri, 3 May 2019 23:15:30 +0200 Subject: [PATCH] make gif square with dark background --- stdplugins/gifs_to_stickers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdplugins/gifs_to_stickers.py b/stdplugins/gifs_to_stickers.py index 011162d..818b78c 100644 --- a/stdplugins/gifs_to_stickers.py +++ b/stdplugins/gifs_to_stickers.py @@ -22,8 +22,10 @@ async def convert_sticker_to_gif(sticker): # remove alpha im = Image.open(file) alpha = im.convert('RGBA').getchannel('A') - new_im = Image.new('RGBA', im.size, (255, 255, 255, 255)) - new_im.paste(im, mask=alpha) + size = max(im.width, im.height) + new_im = Image.new('RGBA', (size, size), (40, 40, 40, 255)) + xy = (round((size - im.width) / 2), round((size - im.height) / 2)) + new_im.paste(im, box=xy, mask=alpha) file = BytesIO() new_im.save(file, format='gif') file.seek(0)