I have a bash oneliner where I pipe one image through the same ImageMagick operation several times. I would like to do this as a Bash loop instead, preferably without using temp files.
The oneliner is: cat in.jpg | convert -quality 1 - jpg:- | convert -quality 1 - jpg:- | convert -quality 1 - jpg:- > out.jpg
This one also works: (convert -quality 1 - jpg:- | convert -quality 1 - jpg:- | convert -quality 1 - jpg:-) > out.jpg < in.jpg
In the convert command the - means "read from stdin" and jpg:- means "output in JPEG format to stdout".
I've tried doing cat in.jpg | for x in {1..3}; do convert -quality 1 - jpg:-; done > out.jpg and (for x in {1..3}; do convert -quality 1 - jpg:-; done) < in.jpg > out.jpg, but both give the same error.
I expect to get the output file with all 3 operations applied to it, but instead I get the output file with just one operation applied to it and the following errors, which I take to mean that the first iteration get to read the in.jpg file, but that the following iterations don't get anything on stdin:
convert: no decode delegate for this image format `' @ > error/constitute.c/ReadImage/501.
convert: no images defined `jpg:-' @ error/convert.c/ConvertImageCommand/3210.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
convert: no images defined `jpg:-' @ error/convert.c/ConvertImageCommand/3210.
(I confirmed that it's only the first iteration that touches the output file by running (for x in 90 30 1; do convert -quality $x - jpg:-; done) < in.jpg > out.jpg