mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 01:34:24 +03:00
Don't copy input file for GS if not necessary, length variable name fix
This commit is contained in:
parent
6dc276599e
commit
81076d5f29
|
@ -86,26 +86,32 @@ def Ghostscript(tile, size, fp, scale=1):
|
||||||
|
|
||||||
out_fd, outfile = tempfile.mkstemp()
|
out_fd, outfile = tempfile.mkstemp()
|
||||||
os.close(out_fd)
|
os.close(out_fd)
|
||||||
in_fd, infile = tempfile.mkstemp()
|
|
||||||
os.close(in_fd)
|
infile_temp = None
|
||||||
|
if hasattr(fp, 'name') and os.path.exists(fp.name):
|
||||||
# ignore length and offset!
|
infile = fp.name
|
||||||
# ghostscript can read it
|
else:
|
||||||
# copy whole file to read in ghostscript
|
in_fd, infile_temp = tempfile.mkstemp()
|
||||||
with open(infile, 'wb') as f:
|
os.close(in_fd)
|
||||||
# fetch length of fp
|
infile = infile_temp
|
||||||
fp.seek(0, 2)
|
|
||||||
fsize = fp.tell()
|
# ignore length and offset!
|
||||||
# ensure start position
|
# ghostscript can read it
|
||||||
# go back
|
# copy whole file to read in ghostscript
|
||||||
fp.seek(0)
|
with open(infile_temp, 'wb') as f:
|
||||||
lengthfile = fsize
|
# fetch length of fp
|
||||||
while lengthfile > 0:
|
fp.seek(0, 2)
|
||||||
s = fp.read(min(lengthfile, 100*1024))
|
fsize = fp.tell()
|
||||||
if not s:
|
# ensure start position
|
||||||
break
|
# go back
|
||||||
length -= len(s)
|
fp.seek(0)
|
||||||
f.write(s)
|
lengthfile = fsize
|
||||||
|
while lengthfile > 0:
|
||||||
|
s = fp.read(min(lengthfile, 100*1024))
|
||||||
|
if not s:
|
||||||
|
break
|
||||||
|
lengthfile -= len(s)
|
||||||
|
f.write(s)
|
||||||
|
|
||||||
# Build ghostscript command
|
# Build ghostscript command
|
||||||
command = ["gs",
|
command = ["gs",
|
||||||
|
@ -136,7 +142,8 @@ def Ghostscript(tile, size, fp, scale=1):
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
os.unlink(outfile)
|
os.unlink(outfile)
|
||||||
os.unlink(infile)
|
if infile_temo:
|
||||||
|
os.unlink(infile_temp)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
return im
|
return im
|
||||||
|
|
Loading…
Reference in New Issue
Block a user