From 66d88bef7ad02a9e05d0f07bfd065aac9979fa16 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Thu, 16 Jul 2020 15:42:23 +0200 Subject: [PATCH] fxconv: better support for indexed images Indexed images don't have an alpha channel, so the detection of transparent pixels in fxconv failed. This change forces a conversion of indexed images to RGBA to properly handle this. --- fxconv/fxconv.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fxconv/fxconv.py b/fxconv/fxconv.py index 255db92..913fc0f 100644 --- a/fxconv/fxconv.py +++ b/fxconv/fxconv.py @@ -737,6 +737,11 @@ def quantize(img, dither=False): palette.putpixel((i, 0), c) palette = palette.convert("P") + # Make the image RGBA in case it was indexed so that transparent pixels are + # represented in an alpha channel + if img.mode == "P": + img = img.convert("RGBA") + # Save the alpha channel, and make it either full transparent or opaque try: alpha_channel = img.getchannel("A").convert("1", dither=Image.NONE)