#!/usr/bin/perl -w
#
# ps2gif [resolution] file...
#
# Convert a postscript file to GIF.  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>

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

if (($R = $ARGV[0]) =~ /^\d+$/) {shift @ARGV} else {$R = 85}

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$R -sOutputFile='|pnmcrop|ppmtogif -interlace >$G' -- $F";
}
