diff --git a/gui/wxpython/psmap/dialogs.py b/gui/wxpython/psmap/dialogs.py index 931d9fe03d7..72a73b0019d 100644 --- a/gui/wxpython/psmap/dialogs.py +++ b/gui/wxpython/psmap/dialogs.py @@ -36,7 +36,6 @@ import os import string -import sys from copy import deepcopy import wx @@ -5947,10 +5946,6 @@ def OnImageSelectionChanged(self, event): if os.path.splitext(file)[1].lower() == ".eps": try: pImg = PILImage.open(file) - if sys.platform == "win32": - import types - - pImg.load = types.MethodType(loadPSForWindows, pImg) img = PilImageToWxImage(pImg) except IOError as e: GError(message=_("Unable to read file %s") % file) diff --git a/gui/wxpython/psmap/frame.py b/gui/wxpython/psmap/frame.py index 70db9fe0b1a..999907b4921 100644 --- a/gui/wxpython/psmap/frame.py +++ b/gui/wxpython/psmap/frame.py @@ -469,12 +469,6 @@ def OnCmdDone(self, event): im_array = np.array(im) im = PILImage.fromarray(np.rot90(im_array, 3)) - - # hack for Windows, change method for loading EPS - if sys.platform == "win32": - import types - - im.load = types.MethodType(loadPSForWindows, im) im.save(self.imgName, format="PNG") except (IOError, OSError) as e: del busy @@ -2472,11 +2466,6 @@ def DrawGraphics( def DrawBitmap(self, pdc, filePath, rotation, bbox): """Draw bitmap using PIL""" pImg = PILImage.open(filePath) - if sys.platform == "win32" and "eps" in os.path.splitext(filePath)[1].lower(): - import types - - pImg.load = types.MethodType(loadPSForWindows, pImg) - if rotation: # get rid of black background pImg = pImg.convert("RGBA") diff --git a/gui/wxpython/psmap/utils.py b/gui/wxpython/psmap/utils.py index de07c4d109a..13eb44986ea 100644 --- a/gui/wxpython/psmap/utils.py +++ b/gui/wxpython/psmap/utils.py @@ -15,13 +15,11 @@ @author Anna Kratochvilova """ -import os import wx -import string from math import ceil, floor, sin, cos, pi try: - from PIL import Image as PILImage + from PIL import Image as PILImage # noqa havePILImage = True except ImportError: @@ -452,66 +450,3 @@ def BBoxAfterRotation(w, h, angle): width = int(ceil(abs(x_max) + abs(x_min))) height = int(ceil(abs(y_max) + abs(y_min))) return width, height - - -# hack for Windows, loading EPS works only on Unix -# these functions are taken from EpsImagePlugin.py - - -def loadPSForWindows(self): - # Load EPS via Ghostscript - if not self.tile: - return - self.im = GhostscriptForWindows(self.tile, self.size, self.fp) - self.mode = self.im.mode - self.size = self.im.size - self.tile = [] - - -def GhostscriptForWindows(tile, size, fp): - """Render an image using Ghostscript (Windows only)""" - # Unpack decoder tile - decoder, tile, offset, data = tile[0] - length, bbox = data - - import tempfile - - file = tempfile.mkstemp()[1] - - # Build ghostscript command - for Windows - command = [ - "gswin32c", - "-q", # quite mode - "-g%dx%d" % size, # set output geometry (pixels) - "-dNOPAUSE -dSAFER", # don't pause between pages, safe mode - "-sDEVICE=ppmraw", # ppm driver - "-sOutputFile=%s" % file, # output file - ] - - command = string.join(command) - - # push data through ghostscript - try: - gs = os.popen(command, "w") - # adjust for image origin - if bbox[0] != 0 or bbox[1] != 0: - gs.write("%d %d translate\n" % (-bbox[0], -bbox[1])) - fp.seek(offset) - while length > 0: - s = fp.read(8192) - if not s: - break - length = length - len(s) - gs.write(s) - status = gs.close() - if status: - raise IOError("gs failed (status %d)" % status) - im = PILImage.core.open_ppm(file) - - finally: - try: - os.unlink(file) - except: - pass - - return im