mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Merge pull request #1523 from radarhere/pilprint
Added subprocess.Popen to pilprint script
This commit is contained in:
commit
46b9bbde87
15
Scripts/pilprint.py
Normal file → Executable file
15
Scripts/pilprint.py
Normal file → Executable file
|
@ -15,6 +15,7 @@ from __future__ import print_function
|
||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import subprocess
|
||||||
|
|
||||||
VERSION = "pilprint 0.3/2003-05-05"
|
VERSION = "pilprint 0.3/2003-05-05"
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ except getopt.error as v:
|
||||||
print(v)
|
print(v)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
printer = None # print to stdout
|
printerArgs = [] # print to stdout
|
||||||
monochrome = 1 # reduce file size for most common case
|
monochrome = 1 # reduce file size for most common case
|
||||||
|
|
||||||
for o, a in opt:
|
for o, a in opt:
|
||||||
|
@ -60,10 +61,10 @@ for o, a in opt:
|
||||||
monochrome = 0
|
monochrome = 0
|
||||||
elif o == "-p":
|
elif o == "-p":
|
||||||
# default printer channel
|
# default printer channel
|
||||||
printer = "lpr"
|
printerArgs = ["lpr"]
|
||||||
elif o == "-P":
|
elif o == "-P":
|
||||||
# printer channel
|
# printer channel
|
||||||
printer = "lpr -P%s" % a
|
printerArgs = ["lpr","-P%s" % a]
|
||||||
|
|
||||||
for filepath in argv:
|
for filepath in argv:
|
||||||
try:
|
try:
|
||||||
|
@ -76,8 +77,9 @@ for filepath in argv:
|
||||||
im.draft("L", im.size)
|
im.draft("L", im.size)
|
||||||
im = im.convert("L")
|
im = im.convert("L")
|
||||||
|
|
||||||
if printer:
|
if printerArgs:
|
||||||
fp = os.popen(printer, "w")
|
p = subprocess.Popen(printerArgs, stdin=subprocess.PIPE)
|
||||||
|
fp = p.stdin
|
||||||
else:
|
else:
|
||||||
fp = sys.stdout
|
fp = sys.stdout
|
||||||
|
|
||||||
|
@ -91,6 +93,9 @@ for filepath in argv:
|
||||||
ps.image(letter, im)
|
ps.image(letter, im)
|
||||||
ps.end_document()
|
ps.end_document()
|
||||||
|
|
||||||
|
if printerArgs:
|
||||||
|
fp.close()
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print("cannot print image", end=' ')
|
print("cannot print image", end=' ')
|
||||||
print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))
|
print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user