]> git.wh0rd.org - home.git/blame_incremental - .bin/imgcrush
cros-board: update
[home.git] / .bin / imgcrush
... / ...
CommitLineData
1#!/bin/bash
2
3usage() {
4 cat <<EOF
5Usage: imgcrush [options] <files>
6EOF
7 exit ${1:-0}
8}
9
10crush_jpg() {
11 local img="$1"
12 jpegoptim "${img}"
13}
14
15crush_png() {
16 local img="$1"
17 # apngopt likes to corrupt images.
18 pngcrush -e .png.new "${img}"
19 mv "${img}.new" "${img}"
20}
21
22crush() {
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
30main() {
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}
42main "$@"