When pngcrush is running in parallell (e.g. starting multiple instances of pngcrush in the background), and using the -ow option, pngcrush will have a file name conflict and overwrite images with the wrong image.
This short little bash script demonstrates the issue:
1 2 3 4 5 6 7 8 9 10 11 12 | #!/bin/bash ITEMS=100 for i in $(seq 1 $ITEMS) do convert -background white -fill black -size 165x70 -pointsize 48 -gravity center label:$i $i.png done for i in $(seq 1 $ITEMS) do pngcrush -q -rem alla -reduce -brute -ow $i.png & done wait |
It first generates 100 PNG images with their number inside. The pngcrush is started in parallell in overwrite mode on each file. Since pngcrush uses the same temporary file name for all the files it is processing, it will in some cases overwrite the files with the wrong minified file.
When pngcrush is not run in -ow mode, this problem goes away, so this works:
pngcrush -q -rem alla -reduce -brute $i.png out/$i.png & mv out/$i.png $i.png
You should take steps to ensure you are creating a real temporary file name, and not reusing the same temporary file name.
This was extremely complex to figure out when the parallelism was lower (4), and was thus rarer and was only detected after the fact.
It's a known issue. See the pngcrush -help screen:
So your command should be
(BTW, the "-reduce" option is no longer needed starting with pngcrush-1.8.0)
Last edit: Glenn Randers-Pehrson 2016-01-28