#!/bin/sh
#
# Use Ghostscript to convert PS to PNG
#
if [ $# != 2 ]; then
	echo usage: $0 in.ps out.png
	exit 1
fi

in="$1"
out="$2"
bbox=`grep ^%%BoundingBox $in`

IFS=" "
set $bbox
if [ "$1" != "%%BoundingBox:" ]; then
	echo "ERROR: can't find BoundingBox in $in"
	exit 1
fi

w=`expr $2 + $4`
h=`expr $3 + $5`

gs -sDEVICE=pnggray -sOutputFile=$out \
	-dBATCH -dNOPAUSE -dTextAlphaBits=4 -dGraphicsAlphaBits=4 \
	-g${w}x${h} -f $in
