]> git.saurik.com Git - cydia.git/blob - pngcrush.sh
Move a bunch of clearly shared logic into CyteKit.
[cydia.git] / pngcrush.sh
1 #!/bin/bash
2
3 png=$1
4 out=$2
5
6 steps=()
7
8 src=${out}.src.png
9 dst=${out}.dst.png
10
11 copy=("${src}" "${dst}")
12
13 function step() {
14 "$@"
15 mv -f "${dst}" "${src}"
16 steps+=($(stat -f "%z" "${src}"))
17 }
18
19 pngcrush=$(xcode-select --print-path)/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush
20
21 if grep CgBI "${png}" &>/dev/null; then
22 if [[ ${png} != ${out} ]]; then
23 cp -a "${png}" "${out}"
24 fi
25
26 exit 0
27 fi
28
29 step cp -fa "${png}" "${dst}"
30
31 #step "${pngcrush}" -q -rem alla -reduce -brute -iphone "${copy[@]}"
32
33 #step "${pngcrush}" -q -rem alla -reduce -brute "${copy[@]}"
34 #step pincrush "${copy[@]}"
35
36 step "${pngcrush}" -q -rem alla -reduce -iphone "${copy[@]}"
37
38 #"${pngcrush}" -q -rem alla -reduce -brute -iphone "${png}" 1.png
39 #"${pngcrush}" -q -iphone _.png 2.png
40 #ls -la 1.png 2.png
41
42 mv -f "${src}" "${out}"
43
44 echo -n "${png##*/} "
45 for ((i = 0; i != ${#steps[@]}; ++i)); do
46 if [[ $i != 0 ]]; then
47 echo -n " "
48 fi
49
50 echo -n "${steps[i]}"
51 done
52
53 printf $' %.0f%%\n' "$((steps[${#steps[@]}-1] * 100 / steps[0]))"