From cd41ab4c5e5edf7e4ba0a4d2866585fdd90a32e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 20 Apr 2024 12:26:21 +0200 Subject: [PATCH] Always convert image to RGB format Closes #13206 --- modules/product_image/product.py | 4 ++-- trytond/trytond/ir/avatar.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/product_image/product.py b/modules/product_image/product.py index a515bf8087..f7e7696edb 100644 --- a/modules/product_image/product.py +++ b/modules/product_image/product.py @@ -171,8 +171,8 @@ class ImageMixin(_ImageMixin): data = io.BytesIO() img = PIL.Image.open(io.BytesIO(image)) img.thumbnail((SIZE_MAX, SIZE_MAX)) - if img.mode in {'RGBA', 'P'}: - img.convert('RGBA') + if img.mode != 'RGB': + img = img.convert('RGB') background = PIL.Image.new('RGBA', img.size, (255, 255, 255)) background.alpha_composite(img) img = background.convert('RGB') diff --git a/trytond/trytond/ir/avatar.py b/trytond/trytond/ir/avatar.py index 3aab60c5be..ed18c2edb6 100644 --- a/trytond/trytond/ir/avatar.py +++ b/trytond/trytond/ir/avatar.py @@ -128,8 +128,8 @@ class Avatar(ImageMixin, ResourceMixin, ModelSQL): (height + size) // 2)) if size > 2048: img = img.resize((2048, 2048)) - if img.mode in {'RGBA', 'P'}: - img.convert('RGBA') + if img.mode != 'RGB': + img = img.convert('RGB') background = Image.new('RGBA', img.size, (255, 255, 255)) background.alpha_composite(img) img = background.convert('RGB')