]> git.wh0rd.org - home.git/blob - .bin/imgcrush
cros-board: update
[home.git] / .bin / imgcrush
1 #!/bin/bash
2
3 usage() {
4 cat <<EOF
5 Usage: imgcrush [options] <files>
6 EOF
7 exit ${1:-0}
8 }
9
10 crush_jpg() {
11 local img="$1"
12 jpegoptim "${img}"
13 }
14
15 crush_png() {
16 local img="$1"
17 # apngopt likes to corrupt images.
18 pngcrush -e .png.new "${img}"
19 mv "${img}.new" "${img}"
20 }
21
22 crush() {
23 case $1 in
24 *.jpg|*.jpeg) crush_jpg "$1" ;;
25 *.png) crush_png "$1" ;;
26 *) echo "${0##*/}: unsupported format: $1" >&2 ;;
27 esac
28 }
29
30 main() {
31 set -e
32
33 while [[ $# -ne 0 ]] ; do
34 case $1 in
35 -h) usage ;;
36 -x) set -x; shift ;;
37 -*) usage 1 ;;
38 *) crush "$1"; shift ;;
39 esac
40 done
41 }
42 main "$@"