diff --git a/modules/product_image/product.py b/modules/product_image/product.py index 93800831ba..e06c6f8e76 100644 --- a/modules/product_image/product.py +++ b/modules/product_image/product.py @@ -170,7 +170,10 @@ class ImageMixin(_ImageMixin): img = PIL.Image.open(io.BytesIO(image)) img.thumbnail((SIZE_MAX, SIZE_MAX)) if img.mode in {'RGBA', 'P'}: - img = img.convert('RGB') + img.convert('RGBA') + background = PIL.Image.new('RGBA', img.size, (255, 255, 255)) + background.alpha_composite(img) + img = background.convert('RGB') img.save(data, format='jpeg', optimize=True, **_params) return data.getvalue() diff --git a/trytond/trytond/ir/avatar.py b/trytond/trytond/ir/avatar.py index 50e896b75c..3aab60c5be 100644 --- a/trytond/trytond/ir/avatar.py +++ b/trytond/trytond/ir/avatar.py @@ -129,7 +129,10 @@ class Avatar(ImageMixin, ResourceMixin, ModelSQL): if size > 2048: img = img.resize((2048, 2048)) if img.mode in {'RGBA', 'P'}: - img = img.convert('RGB') + img.convert('RGBA') + background = Image.new('RGBA', img.size, (255, 255, 255)) + background.alpha_composite(img) + img = background.convert('RGB') img.save(data, format='jpeg', optimize=True, **_params) return data.getvalue()