diff options
Diffstat (limited to '2ff')
-rwxr-xr-x | 2ff | 42 |
1 files changed, 22 insertions, 20 deletions
@@ -1,36 +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" -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 "$FORMAT" in -image/png) - png2ff < "$TMP" - ;; -image/jpeg) - jpg2ff < "$TMP" - ;; -*) - convert "$TMP" png:- 2>/dev/null | png2ff 2>/dev/null - ;; -esac + case "$MIME" in + image/png) + png2ff < "$TMP" + ;; + image/jpeg) + jpg2ff < "$TMP" + ;; + *) + convert "$TMP" png:- 2>/dev/null | png2ff 2>/dev/null + ;; + 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 |