From 836e3e05d8644d4f65c44a1aa02d953762900615 Mon Sep 17 00:00:00 2001 From: David Schmidt Date: Tue, 9 Apr 2013 13:21:38 +0200 Subject: [PATCH] create a palette before converting transparent L-Mode to RGBA fixes #154 --- PIL/Image.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/PIL/Image.py b/PIL/Image.py index 1e29db198..cafc5a22f 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -713,6 +713,16 @@ class Image: if dither is None: dither = FLOYDSTEINBERG + # fake a P-mode image, otherwise the transparency will get lost as there is + # currently no other way to convert transparency into an RGBA image + if self.mode == "L" and mode == "RGBA" and "transparency" in self.info: + from PIL import ImagePalette + self.mode = "P" + bytePalette = bytes([i//3 for i in range(768)]) + self.palette = ImagePalette.raw("RGB", bytePalette) + self.palette.dirty = 1 + self.load() + try: im = self.im.convert(mode, dither) except ValueError: