For a all files in a specified directory with a specified filter (png|gif|jpe?g)
(! with \0
separator to avoid filenames with spaces problems), I wanted to see if the "optimized" webp
file exists, and if not, convert it.
I know what follows can be optimized, etc. but I just want to make it work.
If you have a better solution (with explanation!) this can be interesting too, of course.
IFS= readarray -t -d '' tab < <(find . -type f -print0 | grep -zZE "(png|gif|jpe?g)$") && for f in "${tab[@]}"; do if [ ! -f "$f.webp" ]; then cwebp -q 80 "$f" -o "$f.webp"; fi done
Here's what I did: I'm making an array via readarray
of all found files that match my pattern. Then I do a loop on them, where I test if the file exists. If not, I call cwebp -q 80 "$f" -o "$f.webp";
This one doesn't work with the following errors. Why?
Error! Could not process file ./08/10700_header.jpg
Error! Cannot read input picture file './08/10700_header.jpg'
Error! Could not process file ./08/205790_header.jpg
Error! Cannot read input picture file './08/205790_header.jpg'
parallel
? – Olivier Pons Apr 19 '20 at 11:56parallel
... but your suggestion is so good that if I could I would up your answer once again. Thanks a lot! – Olivier Pons Apr 19 '20 at 16:31