2ff - farbfeld - suckless image format with conversion tools
(HTM) git clone git://git.suckless.org/farbfeld
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
2ff (528B)
---
1 #!/bin/sh
2
3 # arguments
4 if [ "$#" -ne 0 ]; then
5 echo "usage: $0" >&2
6 exit 1
7 fi
8
9 # write input into temporary file
10 TMP=$(mktemp)
11 trap 'rm "$TMP"' EXIT
12 cat > "$TMP"
13
14 # determine the mime-type
15 if [ "$(dd if="$TMP" bs=1 count=8 2>/dev/null | tr -d '\0')" = "farbfeld" ]; then
16 cat "$TMP"
17 else
18 MIME=$(file -ib "$TMP" | cut -d ";" -f 1)
19
20 case "$MIME" in
21 image/png)
22 png2ff < "$TMP"
23 ;;
24 image/jpeg)
25 jpg2ff < "$TMP"
26 ;;
27 *)
28 convert "$TMP" png:- | png2ff
29 ;;
30 esac
31 fi
32
33 # errors
34 if [ $? -ne 0 ]; then
35 exit 1
36 else
37 exit 0
38 fi