From f79cbe81c9df4af37f424740ab9cf5391bdc9365 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 10 May 2017 05:37:47 +0100 Subject: [PATCH] handshake to set compress_level to minimum if save() is called from show() The last in a series of changes to fix https://github.com/python-pillow/Pillow/issues/2508 --- PIL/ImageShow.py | 1 + PIL/PngImagePlugin.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/PIL/ImageShow.py b/PIL/ImageShow.py index 23e0126a7..c8eeb2145 100644 --- a/PIL/ImageShow.py +++ b/PIL/ImageShow.py @@ -71,6 +71,7 @@ class Viewer(object): base = Image.getmodebase(image.mode) if base != image.mode and image.mode != "1" and image.mode != "RGBA": image = image.convert(base) + image.info['showing'] = True return self.show_image(image, **options) diff --git a/PIL/PngImagePlugin.py b/PIL/PngImagePlugin.py index 5e5eb14c7..0bcbd060f 100644 --- a/PIL/PngImagePlugin.py +++ b/PIL/PngImagePlugin.py @@ -687,6 +687,9 @@ def _save(im, fp, filename, chunk=putchunk, check=0): mode = "%s;%d" % (mode, bits) # encoder options + if (im.info.get('showing', False)): + im.encoderinfo['compress_level'] = 1 + im.info.pop('showing', None) im.encoderconfig = (im.encoderinfo.get("optimize", False), im.encoderinfo.get("compress_level", -1), im.encoderinfo.get("compress_type", -1),