]> git.lyx.org Git - lyx.git/blob - lib/scripts/fig2png.sh
Enable the external inset to output different flavours of latex.
[lyx.git] / lib / scripts / fig2png.sh
1 #! /bin/sh
2 # converts an image from XFIG to PNG format
3 # We go the long route to ensure that the image is of the highest
4 # possible quality.
5
6 # We expect a single arg, the name of the input file.
7 test $# -eq 1 || exit 1
8
9 input=`basename $1`
10 base=`basename ${input} .fig`
11 test ${input} = ${base} && {
12     echo Expecting an XFIG file as input
13     exit 1
14 }
15
16 dir=`dirname $1`
17 base=${dir}/${base}
18
19 # Generate the fig2dev output
20 eps=${base}.eps
21 pstex_t=${base}.pstex_t
22
23 echo Entered FIG2PNG.SH
24
25 fig2dev -Lpstex ${input} ${eps}
26 fig2dev -Lpstex_t -p${base} ${input} ${pstex_t}
27
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
30 # "clean" first.
31 clean_eps=${eps}.$$
32 eps2eps ${eps} ${clean_eps}
33
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/'`
40
41 # Generate the bitmap using the -g option to ensure the size is the same
42 # as the original.
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.
45 png=${base}.png
46 gs -q -dSAFER -dBATCH -dNOPAUSE ${geometry} -sDEVICE=png16m \
47         -sOutputFile=${png} ${clean_eps}
48 rm -f ${clean_eps} ${eps}