[FIX] tools: add support for transparency of PNG images
Fixes #2569 Closes #6260
This commit is contained in:
parent
117238fcc1
commit
bf0630e427
|
@ -129,9 +129,14 @@ 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':
|
||||
# Floyd Steinberg dithering by default
|
||||
image = image.convert('RGBA').convert('P', palette=Image.WEB, colors=256)
|
||||
if alpha:
|
||||
image.putalpha(alpha)
|
||||
elif image.format == 'JPEG':
|
||||
opt.update(optimize=True, quality=80)
|
||||
if fp:
|
||||
|
|
Loading…
Reference in New Issue