带开关的MozJPEG STDIN模式

时间:2015-02-25 21:52:47

标签: 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,stdout=subprocess.PIPE)
    image_results = subp.communicate(input=out_im2.getvalue())

但是,如果我尝试使用开关自定义它(例如" -quality 70"),我无法使其工作。我不确定这是一个错误还是我错过了什么。任何见解将不胜感激:

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>

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

感谢https://github.com/njdoyle “-quality 70”应为“-quality”,“70”。两个参数。

所以:

subp = subprocess.Popen(["/home/ubuntu/mozjpeg/cjpeg", "-quality","70"],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
image_results = subp.communicate(input=out_im2.getvalue())