From 49a521ea149a6ec28ddc228490416d11e59bb08b Mon Sep 17 00:00:00 2001 From: dickreckard Date: Mon, 21 Oct 2019 00:22:26 +0200 Subject: [PATCH] thumbnails png fix couldn't generate thumbnails for png pictures due to different mode (RGBA vs RGB) --- distribusi/distribusi.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/distribusi/distribusi.py b/distribusi/distribusi.py index 77a7a90..198e58d 100644 --- a/distribusi/distribusi.py +++ b/distribusi/distribusi.py @@ -33,6 +33,12 @@ def thumbnail(image, name, args): size = (450, 450) im = Image.open(image) im.thumbnail(size) + + if (im.mode == 'RGBA'): + bg = Image.new('RGBA', im.size, (255,255,255)) + composite = Image.alpha_composite(bg, im) + im=composite.convert('RGB') + output = BytesIO() im.save(output, format='JPEG') im_data = output.getvalue()