diff --git a/openerp/tools/image.py b/openerp/tools/image.py index 4473641b0f6..b64647dbb11 100644 --- a/openerp/tools/image.py +++ b/openerp/tools/image.py @@ -111,16 +111,16 @@ def image_save_for_web(image, fp=None, format=None): opt = dict(format=image.format or format) if image.format == 'PNG': opt.update(optimize=True) + alpha = False + if image.mode in ('RGBA', 'LA') or (image.mode == 'P' and 'transparency' in image.info): + alpha = image.convert('RGBA').split()[-1] if image.mode != 'P': # Get the alpha band alpha = image.split()[-1] # Floyd Steinberg dithering by default image = image.convert('RGBA').convert('P', palette=Image.WEB, colors=256) - # Set all pixel values below 128 to 255 and the rest to 0 - mask = Image.eval(alpha, lambda a: 255 if a <=128 else 0) - # Paste the color of index 255 and use alpha as a mask - image.paste(255, mask) - opt.update(transparency=255) + if alpha: + image.putalpha(alpha) elif image.format == 'JPEG': opt.update(optimize=True, quality=80) if fp: