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

View File

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