From af672b1d7e8a4545400777acdd6ce514f37d6cee Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sat, 20 Sep 2014 10:27:52 -0700 Subject: [PATCH] Fix for handling P + transparency -> RGBA conversions --- PIL/Image.py | 10 ++++++++++ Tests/test_file_png.py | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index 5e1416a33..058511b18 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -867,7 +867,17 @@ class Image: trns = trns_im.getpixel((0,0)) elif self.mode == 'P' and mode == 'RGBA': + t = self.info['transparency'] delete_trns = True + + if isinstance(t, bytes): + self.im.putpalettealphas(t) + elif isinstance(t, int): + self.im.putpalettealpha(t,0) + else: + raise ValueError("Transparency for P mode should" + + " be bytes or int") + if mode == "P" and palette == ADAPTIVE: im = self.im.quantize(colors) diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index e4d495330..b8f5ceb08 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -347,8 +347,8 @@ class TestFilePng(PillowTestCase): im2 = Image.open(f) self.assertIn('transparency', im2.info) - self.assert_image_similar(im2.convert('RGBA'), im.convert('RGBA'), - 16) + self.assert_image_equal(im2.convert('RGBA'), + im.convert('RGBA')) def test_save_icc_profile_none(self): # check saving files with an ICC profile set to None (omit profile)