I have several PNG images in the catalog, and I use optipngto optimize and reduce the size of the image. The problem is that it takes too much time to optimize all files.
optipng
I have a quad-core processor, and I noticed that it optipnguses only one core when I optimize the directory.
This is the code I'm using:
ls -1 | while read line do optipng -o7 "$line" done
Is it possible to execute optipngfor four different files in parallel while reading a directory?
There is another solution, including xargs.
xargs
find some/dir/ -iname '*.png' -print0 | xargs -0 -n 1 -P 4 optipng -o7
-P 4 4 , -n 1 .
-P 4
-n 1
, , , :
find some/dir/ -iname '*.png' | sort | xargs -d \\n -n 1 -P 4 optipng -o7
Joe Lencioni .
: script zopflipng ( , optipng) : zopflipng_in_place
optipng , , n, . n=4 , 4 :
n
n=4
n=0 for image in * do optipng -o7 "$image" & n=$(( $n + 1 )) [ "$n" -eq 4 ] && n=0 && wait done
bg ( n low), . , * for image in *.
*
for image in *
I use optipng with GNU parallel (included with every Linux distribution):
parallel --bar 'optipng {}' ::: file1.png file2.png morefile*.png
Advantage: you have a dashboard showing progress.