]> git.wh0rd.org Git - home.git/blob - .bin/imgcrush
git-rb-all: helper for rebasing all branches
[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         jpegoptim "$1"
12 }
13
14 crush_png() {
15         # apngopt likes to corrupt images.
16         pngcrush -e .png.new "$1"
17         mv "${png}.new" "${png}"
18 }
19
20 crush() {
21         case $1 in
22         *.jpg|*.jpeg) crush_jpg "$1" ;;
23         *.png)        crush_png "$1" ;;
24         *) echo "${0##*/}: unsupported format: $1" >&2 ;;
25         esac
26 }
27
28 main() {
29         set -e
30
31         while [[ $# -ne 0 ]] ; do
32                 case $1 in
33                 -h) usage ;;
34                 -*) usage 1 ;;
35                 *)  crush "$1"; shift ;;
36                 esac
37         done
38 }
39 main "$@"