]> git.wh0rd.org Git - home.git/commitdiff
imgcrush: wrapper around diff crush tools
authorMike Frysinger <vapier@gentoo.org>
Sat, 19 Aug 2017 18:56:12 +0000 (14:56 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sat, 19 Aug 2017 18:56:12 +0000 (14:56 -0400)
.bin/imgcrush [new file with mode: 0755]

diff --git a/.bin/imgcrush b/.bin/imgcrush
new file mode 100755 (executable)
index 0000000..3f04460
--- /dev/null
@@ -0,0 +1,38 @@
+#!/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 "$@"