aboutsummaryrefslogtreecommitdiff
path: root/.repos/farbfeld/2ff
diff options
context:
space:
mode:
authorMarvin Borner2020-06-11 14:53:23 +0200
committerMarvin Borner2020-06-11 14:53:23 +0200
commitcfc61f4fa5a5b2236439ec1ebe416f23e31d8092 (patch)
tree96f4fd5f4d57e6835dd6f105caca30c65d7160e5 /.repos/farbfeld/2ff
parentd05b17617eb83377f980c24f29079229697504cc (diff)
Soo many features added
weeee so much efficiencyyyy
Diffstat (limited to '.repos/farbfeld/2ff')
-rwxr-xr-x.repos/farbfeld/2ff38
1 files changed, 38 insertions, 0 deletions
diff --git a/.repos/farbfeld/2ff b/.repos/farbfeld/2ff
new file mode 100755
index 0000000..6ce91b9
--- /dev/null
+++ b/.repos/farbfeld/2ff
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+# arguments
+if [ "$#" -ne 0 ]; then
+ echo "usage: $0" >&2
+ exit 1
+fi
+
+# write input into temporary file
+TMP=$(mktemp)
+trap 'rm "$TMP"' EXIT
+cat > "$TMP"
+
+# determine the mime-type
+if [ "$(dd if="$TMP" bs=1 count=8 2>/dev/null | tr -d '\0')" = "farbfeld" ]; then
+ cat "$TMP"
+else
+ MIME=$(file -ib "$TMP" | cut -d ";" -f 1)
+
+ case "$MIME" in
+ image/png)
+ png2ff < "$TMP"
+ ;;
+ image/jpeg)
+ jpg2ff < "$TMP"
+ ;;
+ *)
+ convert "$TMP" png:- | png2ff
+ ;;
+ esac
+fi
+
+# errors
+if [ $? -ne 0 ]; then
+ exit 1
+else
+ exit 0
+fi