From f848993c89753304911830cd14d553db59cf4eac Mon Sep 17 00:00:00 2001 From: David Schmidt Date: Tue, 25 Feb 2014 09:50:42 +0100 Subject: [PATCH 1/3] fixes #528 Accept 0 as transparency value. --- PIL/PngImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PIL/PngImagePlugin.py b/PIL/PngImagePlugin.py index a6038d9f2..18abf27d3 100644 --- a/PIL/PngImagePlugin.py +++ b/PIL/PngImagePlugin.py @@ -561,7 +561,7 @@ def _save(im, fp, filename, chunk=putchunk, check=0): transparency = im.encoderinfo.get('transparency',im.info.get('transparency', None)) - if transparency: + if transparency or transparency == 0: if im.mode == "P": # limit to actual palette size alpha_bytes = 2**bits From 0d453d9805f203989ac58815fc88358dadb16a8a Mon Sep 17 00:00:00 2001 From: wiredfool Date: Fri, 28 Feb 2014 16:29:34 -0800 Subject: [PATCH 2/3] Added test for Palette transparency=0 --- Tests/test_file_png.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index e8d2a1208..c17829194 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -251,6 +251,20 @@ def test_trns_rgb(): im = roundtrip(im, transparency=(0, 1, 2)) assert_equal(im.info["transparency"], (0, 1, 2)) +def test_trns_p(): + # Check writing a transparency of 0, issue #528 + im = lena('P') + im.info['transparency']=0 + + f = tempfile("temp.png") + im.save(f) + + im2 = Image.open(f) + assert_true('transparency' in im2.info) + + assert_image_equal(im2.convert('RGBA'), im.convert('RGBA')) + + def test_save_icc_profile_none(): # check saving files with an ICC profile set to None (omit profile) in_file = "Tests/images/icc_profile_none.png" From 7baaf296d27b0a380357efdbbd3789c6e89b37e2 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Fri, 28 Feb 2014 16:32:55 -0800 Subject: [PATCH 3/3] Updated changes --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 8c28bc415..abdf73b33 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ Changelog (Pillow) 2.4.0 (unreleased) ------------------ +- Fixed saving mode P image as a PNG with transparency = palette color 0 + [d-schmidt] + - Improve heuristic used when saving progressive and optimized JPEGs with high quality values [e98cuenc]