diff --git a/modules/product_image/product.py b/modules/product_image/product.py index 86ad2a3b6ee0aeb86d2331424009d553f3b3dd06_bW9kdWxlcy9wcm9kdWN0X2ltYWdlL3Byb2R1Y3QucHk=..0d3441841a98884b4401b8645f1db69491a2e322_bW9kdWxlcy9wcm9kdWN0X2ltYWdlL3Byb2R1Y3QucHk= 100644 --- a/modules/product_image/product.py +++ b/modules/product_image/product.py @@ -171,8 +171,8 @@ 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') @@ -176,7 +176,7 @@ 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) + img.save(data, format='jpeg', optimize=True, dpi=(300, 300), **_params) return data.getvalue() def _resize(self, size=64, **_params): @@ -185,7 +185,7 @@ if isinstance(size, int): size = (size, size) img.thumbnail(size) - img.save(data, format='jpeg', optimize=True, **_params) + img.save(data, format='jpeg', optimize=True, dpi=(300, 300), **_params) return data.getvalue() def _store_cache(self, size, image): diff --git a/trytond/trytond/ir/avatar.py b/trytond/trytond/ir/avatar.py index 86ad2a3b6ee0aeb86d2331424009d553f3b3dd06_dHJ5dG9uZC90cnl0b25kL2lyL2F2YXRhci5weQ==..0d3441841a98884b4401b8645f1db69491a2e322_dHJ5dG9uZC90cnl0b25kL2lyL2F2YXRhci5weQ== 100644 --- a/trytond/trytond/ir/avatar.py +++ b/trytond/trytond/ir/avatar.py @@ -128,8 +128,8 @@ (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') @@ -133,7 +133,7 @@ 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) + img.save(data, format='jpeg', optimize=True, dpi=(300, 300), **_params) return data.getvalue() def _resize(self, size=64, **_params): @@ -142,7 +142,7 @@ data = io.BytesIO() img = Image.open(io.BytesIO(self.image)) img = img.resize((size, size)) - img.save(data, format='jpeg', optimize=True, **_params) + img.save(data, format='jpeg', optimize=True, dpi=(300, 300), **_params) return data.getvalue() def _store_cache(self, size, image): @@ -210,5 +210,5 @@ draw.text( (size / 2, size / 2), letter, fill=white, font=font, anchor='mm') data = io.BytesIO() - image.save(data, format='jpeg', optimize=True) + image.save(data, format='jpeg', optimize=True, dpi=(300, 300)) return data.getvalue()