File: 2ff

package info (click to toggle)
farbfeld 4-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 196 kB
  • sloc: ansic: 622; sh: 65; makefile: 59
file content (44 lines) | stat: -rwxr-xr-x 727 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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"

# 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"
		;;
	*)
		if [ ! -x /usr/bin/convert ] ; then
			printf "%s: cant convert from %s -- missing \`convert' program" "$0" "$MIME" >&2
			printf "Run \`apt install imagemagick' to install it" >&2
			exit 1
		fi

		convert "$TMP" png:- | png2ff
		;;
	esac
fi

# errors
if [ $? -ne 0 ]; then
	exit 1
else
	exit 0
fi