Jpegoptim: Option to output to another filename

Created on 20 May 2014  ·  3Comments  ·  Source: tjko/jpegoptim

Currently you support batch image processing nicely by offering destination directory option, however if a user wants to optimize just a single image with a different file name, he can't. I think having 2 parameters one for input and one for output can help in this case and it seems reasonable to have this support in this awesome optimizer.

Most helpful comment

Starting from v1.4.0, jpegoptim supports stdin/stdout. So, now there is couple ways to do what you want:

jpegoptim --stdout a.jpg > b.jpg

or

cat a.jpg | jpegoptim --stdin > b.jpg

All 3 comments

Starting from v1.4.0, jpegoptim supports stdin/stdout. So, now there is couple ways to do what you want:

jpegoptim --stdout a.jpg > b.jpg

or

cat a.jpg | jpegoptim --stdin > b.jpg

To use stdin/stdout you have to use a shell. The binary itself is not capable of outputting to another filename, which in my opinion is a weakness/missing feature.

If anyone is stuck with this, you can get a little creative by doing this.

  1. Create a copy of your original image and rename it to your intended output file name.
  2. Optimize the copied version of your original image.

Here is a small bash script:

img='test.jpg'
cp $img ${img%.*}-optimized.jpg
jpegoptim ${img%.*}-optimized.jpg
Was this page helpful?
0 / 5 - 0 ratings

Related issues

szepeviktor picture szepeviktor  ·  11Comments

alswl picture alswl  ·  3Comments

mapreferee picture mapreferee  ·  3Comments

ydahhrk picture ydahhrk  ·  3Comments

makoConstruct picture makoConstruct  ·  3Comments