#!/usr/bin/perl -w
#
# ps2gif [resolution] file...

# Convert  a postscript file to GIF, using the gs (GhostScript) command.  The
# resolution defaults to  100,  which  is  a  readable  compromise  for  most
# screens.   The files should be postscript files.  You can omit a .ps suffix
# and we'll assume it.
#
# Author: John Chambers <jc@trillian.mit.edu>

#GS = '/usr/local/bin/gs';

$ENV{LD_LIBRARY_PATH} = '/usr/X11R6/lib/:/usr/eecs/lib:/usr/lib:/usr/lib/aout';

($hres = (shift) . ' 100') =~ /(\d+)/; $hres = $1;
($vres = (shift) . ' 100') =~ /(\d+)/; $vres = $1;

file: for $f (@ARGV) {
	if ($f =~ /(.*)\.(\w*ps)$/i) {
		$F = $f;
		$G = "$1.gif";
	} else {
		if      (-f ($F = "$f.ps" )) {$G = "$f.gif";
		} elsif (-f ($F = "$f.eps")) {$G = "$f.gif";
		} elsif (-f ($F = "$f.PS" )) {$G = "$f.GIF";
		} else {
			print STDERR "Can't find postscript file for $f.\n";
			next file;
		}
	}
	system "gs -q -DNOPAUSE -sDEVICE=ppmraw -r${hres}x${vres} -sOutputFile='|pnmcrop|ppmtogif -interlace >$G' -- $F";
}
