File: any2xpm

package info (click to toggle)
mowitz 0.2.0-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,168 kB
  • ctags: 4,214
  • sloc: ansic: 30,869; sh: 9,051; makefile: 169
file content (61 lines) | stat: -rwxr-xr-x 1,295 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
#!/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.

# This is where netpbm installs itself by default
PATH="$PATH:/usr/local/netpbm/bin"
export PATH

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"