带开关的MozJPEG标准输入模式

2024-09-22 20:25:24 发布

您现在位置:Python中文网/ 问答频道 /正文

如果不使用任何标志,我可以让stdin/out在mozjpeg 3上正常工作。 示例(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”)来定制它,我就不能让它工作。我不确定这是一个错误还是我遗漏了什么。如有任何见解,我们将不胜感激:

^{pr2}$

在此执行后,我收到以下回执:

/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>

提前谢谢你的帮助。在


Tags: lthomeubuntustdinoutlibssubprocessquality
1条回答
网友
1楼 · 发布于 2024-09-22 20:25:24

感谢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())

相关问题 更多 >