From 7989378bfdf44457f0a997ca932441a99f3d950e Mon Sep 17 00:00:00 2001 From: Esteban Santana Santana Date: Sun, 17 Nov 2013 01:26:44 -0600 Subject: [PATCH] Added a way to specify the render size for EPS files. There is now a scale parameter that you can pass in to the EpsImageFile.load() function. This parameter is used to specify at what scale Ghostscript renders the EPS internally. Scale needs to be an integer, and all of the internal structures (image size and bounding box) are scaled based on that parameter. --- PIL/EpsImagePlugin.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/PIL/EpsImagePlugin.py b/PIL/EpsImagePlugin.py index bc0ed43c5..1c9c4b6a1 100644 --- a/PIL/EpsImagePlugin.py +++ b/PIL/EpsImagePlugin.py @@ -50,13 +50,21 @@ if sys.platform.startswith('win'): else: gs_windows_binary = False -def Ghostscript(tile, size, fp): +def Ghostscript(tile, size, fp, scale=1): """Render an image using Ghostscript""" # Unpack decoder tile decoder, tile, offset, data = tile[0] length, bbox = data + #Hack to support hi-res rendering + scale = int(scale) or 1 + orig_size = size + orig_bbox = bbox + size = (size[0] * scale, size[1] * scale) + bbox = [bbox[0], bbox[1], bbox[2] * scale, bbox[3] * scale] + #print("Ghostscript", scale, size, orig_size, bbox, orig_bbox) + import tempfile, os file = tempfile.mktemp() @@ -65,6 +73,7 @@ def Ghostscript(tile, size, fp): command = ["gs", "-q", # quite mode "-g%dx%d" % size, # set output geometry (pixels) + "-r%d" % (72*scale), # set input DPI (dots per inch) "-dNOPAUSE -dSAFER", # don't pause between pages, safe mode "-sDEVICE=ppmraw", # ppm driver "-sOutputFile=%s" % file,# output file @@ -304,11 +313,11 @@ class EpsImageFile(ImageFile.ImageFile): if not box: raise IOError("cannot determine EPS bounding box") - def load(self): + def load(self, scale=1): # Load EPS via Ghostscript if not self.tile: return - self.im = Ghostscript(self.tile, self.size, self.fp) + self.im = Ghostscript(self.tile, self.size, self.fp, scale) self.mode = self.im.mode self.size = self.im.size self.tile = []