mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
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.
This commit is contained in:
parent
f44f4efb68
commit
7989378bfd
|
@ -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 = []
|
||||
|
|
Loading…
Reference in New Issue
Block a user