#! /bin/csh
#  pstogif:  From a postscript file to a Gif, 
#         at 72dpi to get "what you see is what you get" display
#
#  usage:  pstogif psfilename giffilename
#
#	Note:  Due to aliasing and lousy fonts, this won't come 
#	close to what you can do by hand with a program like 
#	PhotoShop or a number of other Mac or PC-based tools.
#
#	The first part of this script is essentially a stripped-down
#	version of pstopnm from the Netpbm package. The last part is 
#	most borrowed from scripts by Doug Crabill.
#
#	The whole script
#	could be replaced with ps2gif, which is part of the fm2html 
#	package.  ps2gif has more options, but also has a more restrictive
#	copyright and requires Perl. 
#
#
### ############################################################### ##
#  This script requires ghostscript and the portable bitmap package. #
#								     #
### ############################################################### ##
#BEGIN CONFIGURE
echo "Script  has not been configured"
echo 'Edit file "Configuration.src", save as "Configuration"'
echo '  and then type "make wwwbin" '
exit(1)
#END CONFIGURE
#
if ($#argv != 2) then 
   echo "Usage: $0 postscript_file_name  gif_file_name"
   exit 1
endif
set source = $1
set target = $2
set tmp = pstogif$$
set base = `basename $source`
##
## Use GhostScript to produce a bitmap file in .ppm format
##
$bindir/crfilt <$source >$tmpdir/$tmp.ps
(cd $tmpdir; $gs -q -dNODISPLAY pstoppm.ps)  <<xxEOFxx
($tmp) ppm8run
xxEOFxx
if (! -f $tmpdir/$tmp.ppm) then
	echo "Ghostscript has let me down"
	exit 2
endif
##
## And then turn that bitmap into a GIF image
## 
$pbmdir/pnmcrop $tmpdir/$tmp.ppm |\
   $pbmdir/ppmtogif -transparent \#ffffff >${target}

$rm $tmpdir/$tmp.ppm
