summaryrefslogtreecommitdiff
path: root/2ff
diff options
context:
space:
mode:
authorParide Legovini <pl@ninthfloor.org>2017-07-16 17:36:46 +0200
committerParide Legovini <pl@ninthfloor.org>2017-07-16 17:36:46 +0200
commit31cb65d7cc6d257bcc725ef39ffbced7b465f0cc (patch)
tree28d325b462a84b8a16bd2e9aa546df75dcd1b664 /2ff
parented0e5905eff7383b05b87ecf1689a6938f9d79d3 (diff)
parent00dd0ab39f634729ec5d99b8057b9cef6fa0f23e (diff)
Merge tag '3'
Diffstat (limited to '2ff')
-rwxr-xr-x2ff51
1 files changed, 27 insertions, 24 deletions
diff --git a/2ff b/2ff
index f958692..10e4320 100755
--- a/2ff
+++ b/2ff
@@ -1,41 +1,44 @@
#!/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"
-if [ "$(dd if="$TMP" bs=1 count=8 2>/dev/null)" = "farbfeld" ]; then
+# determine the mime-type
+if [ "$(dd if="$TMP" bs=1 count=8 2>/dev/null | tr -d '\0')" = "farbfeld" ]; then
cat "$TMP"
- exit 0
-fi
+else
+ MIME=$(file -ib "$TMP" | cut -d ";" -f 1)
-FORMAT=$(file -ib "$TMP" | cut -d ";" -f 1)
+ case "$MIME" in
+ image/png)
+ png2ff < "$TMP"
+ ;;
+ image/jpeg)
+ jpg2ff < "$TMP"
+ ;;
+ *)
+ if [ ! -x /usr/bin/convert ] ; then
+ printf "%s: cant convert from %s -- missing \`convert' program" "$0" "$FORMAT" >&2
+ printf "Run \`apt-get install imagemagick' to install it" >&2
+ exit 1
+ fi
-case "$FORMAT" in
-image/png)
- png2ff < "$TMP"
- ;;
-image/jpeg)
- jpg2ff < "$TMP"
- ;;
-*)
- if [ ! -x /usr/bin/convert ] ; then
- printf "%s: cant convert from %s -- missing \`convert' program" "$0" "$FORMAT" >&2
- printf "Run \`apt-get install imagemagick' to install it" >&2
- exit 1
- fi
- convert "$TMP" png:- 2>/dev/null | png2ff 2>/dev/null
- ;;
-esac
+ convert "$TMP" png:- | png2ff
+ ;;
+ esac
+fi
+# errors
if [ $? -ne 0 ]; then
- printf "%s: failed to convert from %s\n" "$0" "$FORMAT" >&2
exit 1
+else
+ exit 0
fi
-
-exit 0