File: any2xpm

package info (click to toggle)
siag 3.5.1-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,076 kB
  • ctags: 8,908
  • sloc: ansic: 67,975; lisp: 5,435; sh: 3,342; cs: 679; makefile: 550; perl: 404
file content (67 lines) | stat: -rwxr-xr-x 1,372 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh

# Attempt to convert any image file to XPM format. Requires the netpbm
# package for all formats except XPM itself. JPEG also requires the
# djpeg program.

# Compressed files are automatically decompressed before converting.
# Requires gzip and uncompress.

# For unknown extensions, the script falls back to anytopnm which is
# part of netpbm.

# echo "Converting $1" 1>&2

#CONVERT=`which convert` 2> /dev/null
#
#if test -x "$CONVERT" 2> /dev/null; then
#	# echo CONVERT=\"$CONVERT\"
#	$CONVERT "$1" xpm:-
#	exit
#fi

convert_image()
{
	case "$1" in
	*.gz )
		name=`basename "$1" .gz`
		tmpfile=/tmp/DeCoDe_${name}
		cp "$1" "${tmpfile}.gz"
		gzip -df "${tmpfile}.gz"
		convert_image "$tmpfile"
		rm "${tmpfile}"
		;;
	*.Z )
		name=`basename "$1" .Z`
		tmpfile=/tmp/DeCoDe_${name}
		cp "$1" "${tmpfile}.Z"
		uncompress -f "${tmpfile}.Z"
		convert_image "${tmpfile}"
		rm "${tmpfile}"
		;;
	*.gif | *.GIF )
		giftopnm "$1" | ppmtoxpm 2> /dev/null
		;;
	*.jpg | *.jpeg | *.JPG | *.JPEG )
		djpeg -colors 128 "$1" | ppmtoxpm 2> /dev/null
		;;
	*.tif | *.tiff | *.TIF | *.TIFF )
		tifftopnm "$1" | ppmtoxpm 2> /dev/null
		;;
	*.png | *.PNG )
		pngtopnm "$1" | ppmtoxpm 2> /dev/null
		;;
	*.bmp | *.BMP )
		bmptoppm "$1" | ppmtoxpm 2> /dev/null
		;;
	*.xpm | *.XPM )
		cat "$1"
		;;
	* )
		anytopnm "$1" | ppmtoxpm 2> /dev/null
		;;
	esac
}

convert_image "$1"