3 # This script recompressess .png files using pngcrush and
4 # optipng to get the smallest images. All recompression is
7 # NOTE: files must be in same directory as the script is run from!
9 # ~/supertux/tools/image_recompress.sh *.png
11 # ~/supertux/tools/image_recompress.sh */*.png
12 # (bad, does not work)
15 # * Make it work recursivly
16 # * Make it work on files not in current directory
18 if [ -z "$1" ] || [ "$1" == "--help" ]; then
19 echo "Usage: $(basename $0) files..."
20 echo -e '\e[1mNOTE: Files must be in same directory as the script is run from!\e[0m'
25 echo ' this does NOT work'
29 # Check that the tools we use exist:
30 if ! type pngcrush > /dev/null 2>&1; then
31 echo "Can't find pngcrush!"
32 echo "This script depends on the pngcrush tool to be in PATH."
33 echo "Please install it or, if it is already installed add the"
34 echo "directory it is in to PATH and try again."
37 if ! type optipng > /dev/null 2>&1; then
38 echo "Can't find optipng!"
39 echo "This script depends on the optipng tool to be in PATH."
40 echo "Please install it or, if it is already installed add the"
41 echo "directory it is in to PATH and try again."
46 echo -e "Please wait, this can take a \e[1mlong\e[0m time."
48 echo -e "\n\n\n\e[1mPass 1: pngcrush\e[0m\n\n\n"
50 echo -e "\e[1m$image\e[0m : $(du -b $image | awk '{print $1}')"
51 newsize="$(pngcrush -reduce -brute -d c "$image" | grep -E "filesize reduction")"
52 if [[ $newsize =~ ".+reduction.+" ]]; then
54 cp -v "c/$image" "$image"
60 echo -e "\n\n\n\e[1mPass 2: optipng\e[0m\n\n\n"
62 echo -e "\e[1m$image\e[0m : $(du -b $image | awk '{print $1}')"
63 newsize="$(optipng -i 0 -o 7 -dir out "$image" | grep -E '^Output file size')"
65 if [[ $newsize =~ ".+decrease.+" ]]; then
66 cp -v "out/$image" "$image"