I've been trying to use convertDefault.sh to do all my image conversion. However, I have some eps images which cause my version of 'convert' to keel over and die (segfault actually). This is even after I'd run them through eps2eps to ensure that they were conformant. Since this is a stock RH8 system, I guess that others will experience similar problems.
So, I experimented. 'gs' can convert them to ppm or png format without any problems and it's far, far quicker. Some magic is needed, however, to ensure that the generated bitmap file has the same bounding box as the original eps file and isn't padded with arbitrary amounts of whitespace. Fortunately, gs itself provides us with the information we need. I therefore modified convertDefault.sh and attach the patch. What do other's think? Shall we leave convertDefault.sh as a simple fall-back or make it a little more sophisticated? -- Angus
? convert.diff Index: convertDefault.sh =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/scripts/convertDefault.sh,v retrieving revision 1.5 diff -u -p -r1.5 convertDefault.sh --- convertDefault.sh 13 Jan 2003 23:35:18 -0000 1.5 +++ convertDefault.sh 24 Jan 2003 16:55:27 -0000 @@ -6,18 +6,46 @@ # replacement in ~/.lyx/scripts # # converts an image from $1 to $2 format -convert -depth 8 $1 $2 -if [ $? -ne 0 ]; then - exit $? -fi -# It appears that convert succeeded, but we know better than to trust it ;-) # convert is passed strings in the form "FMT:FILENAME", so use the ':' to # delimit the two parts. -FILE=`echo $2 | cut -d ':' -f 2` +FMT_IN=`echo $1 | cut -d ':' -f 1` +FMT_OUT=`echo $2 | cut -d ':' -f 1` +FILE_IN=`echo $1 | cut -d ':' -f 2` +FILE_OUT=`echo $2 | cut -d ':' -f 2` + +# There's no need to use 'convert' if instead we can use 'gs'. +USE_GS=0 +if [ $FMT_IN = "eps" ]; then + if [ $FMT_OUT = "ppm" ]; then + USE_GS=1 + DEVICE=ppmraw + elif [ $FMT_OUT = "png" ]; then + USE_GS=1 + DEVICE=png16m + fi +fi + +if [ $USE_GS -eq 1 ]; then + # Extract the width and height of the image using gs' bbox device. + # Rewrite this info as GEOMETRY='-g<width>x<height>' + GEOMETRY=`gs -dNOPAUSE -dBATCH -sDEVICE=bbox $FILE_IN 2>&1 | \ + sed -n 's/^%%BoundingBox: [0-9]\{1,\} [0-9]\{1,\} \([0-9]\{1,\}\) \([0-9]\{1,\}\)$/-g\1x\2/p'` + # Generate the bitmap using the -g option to ensure the size is the same as the original. + # If we're using a version of gs that does not have a bbox device, then + # $GEOMETRY = "", so there are no unwanted side effects. + gs -dSAFER -dBATCH -dNOPAUSE $GEOMETRY -sDEVICE=$DEVICE -sOutputFile=$FILE_OUT $FILE_IN +else + convert $1 $2 +fi + +if [ $? -ne 0 ]; then + exit $? +fi -# FSTATUS == 0 is the file exists and == 1 if it does not. +# It appears that the conversion succeeded, but we know better than to trust it ;-) +# FSTATUS == 0 is the generated file exists and == 1 if it does not. FSTATUS=0 -test -f $FILE || FSTATUS=1 +test -f $FILE_OUT || FSTATUS=1 exit $FSTATUS