Python 带开关的MozJPEG标准格式

Python 带开关的MozJPEG标准格式,python,popen,stringio,Python,Popen,Stringio,如果我只是在没有任何标志的情况下运行,我就能够使用mozjpeg 3使stdin/out正常工作。 例如Python: fp = urllib.urlopen(http://path.to/unoptimized.jpg) out_im2 = StringIO.StringIO(fp.read()) # StringIO Image subp = subprocess.Popen(["/home/ubuntu/mozjpeg/cjpeg"],stdin=subprocess.PIPE,stdou

如果我只是在没有任何标志的情况下运行,我就能够使用mozjpeg 3使stdin/out正常工作。 例如Python:

fp = urllib.urlopen(http://path.to/unoptimized.jpg)
out_im2 = StringIO.StringIO(fp.read()) # StringIO Image
subp = subprocess.Popen(["/home/ubuntu/mozjpeg/cjpeg"],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
    image_results = subp.communicate(input=out_im2.getvalue())
但是,如果我试图使用Switches(例如-quality 70)来定制它,我就无法让它工作。我不确定这是一个bug还是我遗漏了什么。如有任何见解,将不胜感激:

subp = subprocess.Popen(["/home/ubuntu/mozjpeg/cjpeg", "-quality 70"],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
image_results = subp.communicate(input=out_im2.getvalue())
执行后,我收到以下回复:

/home/ubuntu/mozjpeg/.libs/lt-cjpeg: unknown option 'quality 70'
usage: /home/ubuntu/mozjpeg/.libs/lt-cjpeg [switches] [inputfile]
Switches (names may be abbreviated):
  -quality N[,...]   Compression quality (0..100; 5-95 is useful range)
.... <Rest of --help screen>
提前感谢您的帮助。

谢谢 “-quality 70”应为“-quality”,“70”。两个参数

因此:

为什么要使用out\im2 StringIO而不是直接传递subp.communicateinput=fp.read?你甚至可以。阅读以避免陷入简单的事情。
subp = subprocess.Popen(["/home/ubuntu/mozjpeg/cjpeg", "-quality","70"],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
image_results = subp.communicate(input=out_im2.getvalue())