From dbf7afa084c75d9408f75bd3b3057b93798fbf36 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 8 May 2016 15:51:20 +0530 Subject: [PATCH] Quantize transparent images by blending with white --- src/calibre/utils/img.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index 6d2634c257..739f7cd225 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -282,7 +282,10 @@ def normalize(img): def quantize(img, num_of_colors=256, dither=True): if imageops is None: raise RuntimeError(imageops_err) - return imageops.quantize(image_from_data(img), num_of_colors, dither) + img = image_from_data(img) + if img.hasAlphaChannel(): + img = blend_image(img) + return imageops.quantize(img, num_of_colors, dither) def run_optimizer(file_path, cmd, as_filter=False, input_data=None): file_path = os.path.abspath(file_path)