2 # converts an image from XFIG to PNG format
3 # We go the long route to ensure that the image is of the highest
6 # We expect a single arg, the name of the input file.
7 test $# -eq 1 || exit 1
10 base=`basename ${input} .fig`
11 test ${input} = ${base} && {
12 echo Expecting an XFIG file as input
19 # Generate the fig2dev output
21 pstex_t=${base}.pstex_t
23 echo Entered FIG2PNG.SH
25 fig2dev -Lpstex ${input} ${eps}
26 fig2dev -Lpstex_t -p${base} ${input} ${pstex_t}
28 # Convert the EPS file (free of "special" text) to PNG format using gs
29 # gs is extremely fussy about the EPS files it converts, so ensure it is
32 eps2eps ${eps} ${clean_eps}
34 # Extract the width and height of the image using gs' bbox device.
35 # Ie, take output that includes a line "%%BoundingBox: 0 0 <width> <height>"
36 # and rewrite it as "-g<width>x<height>"
37 geometry=`gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox ${clean_eps} 2>&1 | \
38 sed '/^%%BoundingBox/! d' | cut -d' ' -f4,5 | \
39 sed 's/^\([0-9]\{1,\}\) \([0-9]\{1,\}\)$/-g\1x\2/'`
41 # Generate the bitmap using the -g option to ensure the size is the same
43 # If we're using a version of gs that does not have a bbox device, then
44 # $GEOMETRY = "", so there are no unwanted side effects.
46 gs -q -dSAFER -dBATCH -dNOPAUSE ${geometry} -sDEVICE=png16m \
47 -sOutputFile=${png} ${clean_eps}
48 rm -f ${clean_eps} ${eps}