0

I'm able to get stdin/out working just fine with mozjpeg 3 if I just run without any flags. Example(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())

If, however, I attempt to customize this with switches(For example "-quality 70"), I cannot get it to work. I'm not sure if this is a bug or if I'm missing something. Any insight would be greatly appreciated:

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

Upon this execution, I receive the following back:

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

Thanks in advance for any help.

ryan83
  • 13
  • 4
  • why do you use `out_im2` StringIO instead of passing `subp.communicate(input=fp.read())` directly? You even can [redirect subprocess' stdin from the socket (it works on Ubuntu) without loading it in memory](http://stackoverflow.com/a/28724272/4279). – jfs Feb 26 '15 at 13:56

1 Answers1

0

Thanks to https://github.com/njdoyle “-quality 70” should be “-quality”, “70”. Two parameters.

So:

subp = subprocess.Popen(["/home/ubuntu/mozjpeg/cjpeg", "-quality","70"],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
image_results = subp.communicate(input=out_im2.getvalue())
ryan83
  • 13
  • 4
  • read ["Frequently Used Arguments" section in subprocess' docs](https://docs.python.org/3/library/subprocess.html#frequently-used-arguments) to avoid being stuck on simple things. – jfs Feb 26 '15 at 13:58