Merge pull request #2527 from wiredfool/pr_2509

Use PNG for Image.show()
This commit is contained in:
Hugo 2017-05-13 16:59:20 +03:00 committed by GitHub
commit d1feaf8046
2 changed files with 10 additions and 5 deletions

View File

@ -577,7 +577,7 @@ class Image(object):
self.pyaccess = None
self.readonly = 0
def _dump(self, file=None, format=None):
def _dump(self, file=None, format=None, **options):
import tempfile
suffix = ''
if format:
@ -592,7 +592,7 @@ class Image(object):
else:
if not file.endswith(format):
file = file + "." + format
self.save(file, format)
self.save(file, format, **options)
return file
def __eq__(self, other):

View File

@ -69,7 +69,7 @@ class Viewer(object):
# FIXME: auto-contrast if max() > 255?
else:
base = Image.getmodebase(image.mode)
if base != image.mode and image.mode != "1":
if base != image.mode and image.mode != "1" and image.mode != "RGBA":
image = image.convert(base)
return self.show_image(image, **options)
@ -77,6 +77,7 @@ class Viewer(object):
# hook methods
format = None
options = {}
def get_format(self, image):
"""Return format name, or None to save as PGM/PPM"""
@ -87,7 +88,7 @@ class Viewer(object):
def save_image(self, image):
"""Save to temporary file, and return filename"""
return image._dump(format=self.get_format(image))
return image._dump(format=self.get_format(image), **self.options)
def show_image(self, image, **options):
"""Display given image"""
@ -115,7 +116,8 @@ if sys.platform == "win32":
elif sys.platform == "darwin":
class MacViewer(Viewer):
format = "BMP"
format = "PNG"
options = {'compress-level': 1}
def get_command(self, file, **options):
# on darwin open returns immediately resulting in the temp
@ -142,6 +144,9 @@ else:
return None
class UnixViewer(Viewer):
format = "PNG"
options = {'compress-level': 1}
def show_file(self, file, **options):
command, executable = self.get_command_ex(file, **options)
command = "(%s %s; rm -f %s)&" % (command, quote(file),