--- /dev/null
+#!/bin/bash
+
+usage() {
+ cat <<EOF
+Usage: imgcrush [options] <files>
+EOF
+ exit ${1:-0}
+}
+
+crush_jpg() {
+ jpegoptim "$1"
+}
+
+crush_png() {
+ # apngopt likes to corrupt images.
+ pngcrush -e .png.new "$1"
+ mv "${png}.new" "${png}"
+}
+
+crush() {
+ case $1 in
+ *.jpg|*.jpeg) crush_jpg "$1" ;;
+ *.png) crush_png "$1" ;;
+ esac
+}
+
+main() {
+ set -e
+
+ while [[ $# -ne 0 ]] ; do
+ case $1 in
+ -h) usage ;;
+ -*) usage 1 ;;
+ *) crush "$1" ;;
+ esac
+ done
+}
+main "$@"