#! /bin/sh
# Copyright (C) 2002 Alan McIvor <alan@mcivor.gen.nz>
#  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# Note that you need the psutils package for this to work

# get bounding box (only works because we know there is only 1 such comment)
llx=`awk '$1=="%%BoundingBox:"{print $2}' < $1.eps`
lly=`awk '$1=="%%BoundingBox:"{print $3}' < $1.eps`
urx=`awk '$1=="%%BoundingBox:"{print $4}' < $1.eps`
ury=`awk '$1=="%%BoundingBox:"{print $5}' < $1.eps`
height=$(( $ury - $lly ))
width=$(( $urx - $llx ))

epsffit 0 0 $width $height $1.eps $1.epstemp

gs -q -dNOPAUSE -sDEVICE=png16m -sOutputFile=$1.png -g${width}x${height} \
 $1.epstemp quit.ps

rm -f $1.epstemp
