File indexing completed on 2024-04-06 12:31:46
0001
0002
0003 resolution=72 bbox= showpage= errors=false record=/dev/null recordtitle=
0004 maxsize=1600
0005
0006 while true; do
0007 [ $
0008 case "$1" in
0009 --eps )
0010 showpage="-c showpage" ;;
0011 --ps )
0012 showpage= ;;
0013
0014 --resolution=* )
0015 resolution="`echo \"$1\" | sed 's/^[^=]*=//'`" ;;
0016
0017 --bbox=* )
0018 bbox="` echo \"$1\" | sed 's/^[^=]*=//; s/,/ /'`" ;;
0019
0020 --maxsize=* )
0021 maxsize="`echo \"$1\" | sed 's/^[^=]*=//'`" ;;
0022
0023 --record=* )
0024 record="`echo \"$1\" | sed 's/^[^=]*=//'`" ;;
0025
0026 --record-title=* )
0027 recordtitle="`echo \"$1\" | sed 's/^[^=]*=//'`" ;;
0028
0029 --* )
0030 errors=true ;;
0031 * )
0032 break ;;
0033 esac
0034 shift
0035 done
0036
0037 if [ $
0038 echo "usage: $0 [--eps|--ps] [--resolution=OUT-RES] [--bbox=X,Y] [--record=FILE] [--record-title=TITLE] FILE" 1>&2
0039 exit 1
0040 fi
0041
0042 file="$1"
0043 [ -z "$recordtitle" ] && recordtitle="$file"
0044
0045 if [ -z "$bbox" ]; then
0046 bbox="`grep '%%BoundingBox:' $file | head -1 | sed 's/[ ][ ]*/ /g' | sed 's|^.*: *||;s| *$||'`"
0047 if [ X"$bbox" = 'X(atend)' ] ; then
0048 bbox="`grep '%%BoundingBox:' $file | tail -1 | sed 's/[ ][ ]*/ /g' |sed 's|^.*: *||;s| *$||'`"
0049 fi
0050 bbox="`echo $bbox | sed 's/^[0-9][0-9]* [0-9][0-9]* //; s/[ ]*$//'`"
0051 fi
0052
0053 xres="`echo \"$bbox\" | sed 's/ .*//'`"
0054 yres="`echo \"$bbox\" | sed 's/.* //'`"
0055
0056 if [ -z "$xres" -o -z "$yres" ]; then
0057 echo "$file: error: cannot determine bounding box" 1>&2
0058 exit 1
0059 fi
0060
0061 scale=1
0062 if [ $xres -ge $maxsize -o $yres -ge $maxsize ]; then
0063 oldxres=$xres oldyres=$yres
0064 max=$xres; [ $yres -gt $xres ] && max=$yres
0065 scale=`expr $maxsize \* 100 / $max`
0066 xres=`expr $xres \* $scale / 100 + 1`
0067 yres=`expr $yres \* $scale / 100 + 1`
0068 if [ $scale -lt 10 ]; then
0069 scale=".0$scale"
0070 else
0071 scale=".$scale"
0072 fi
0073
0074 echo "$file: warning: scaling bounding box ($oldxres, $oldyres) down to ($xres, $yres)" 1>&2
0075 fi
0076
0077 tmp=${TMPDIR-/tmp}/crop$$
0078 rm -f $tmp
0079 gs -q -dSAFER -dBATCH -dNOPAUSE -sDEVICE=ppmraw -dTextAlphaBits=4 \
0080 -dGraphicsAlphaBits=4 -r${resolution}x${resolution} -g${xres}x${yres} \
0081 -sOutputFile=- -c "$scale $scale scale" -f "$file" $showpage -c quit | \
0082 ppmquant 256 2>/dev/null | \
0083 pnmcrop -white -verbose 2>$tmp | \
0084 ppmtogif -interlace -sort 2>/dev/null
0085
0086 top=`grep 'rows off the top' < $tmp | sed 's/.*cropping //; s/ rows.*//'`
0087 bottom=`grep 'rows off the bottom' < $tmp | sed 's/.*cropping //; s/ rows.*//'`
0088 left=`grep 'cols off the left' < $tmp | sed 's/.*cropping //; s/ cols.*//'`
0089 right=`grep 'cols off the right' < $tmp | sed 's/.*cropping //; s/ cols.*//'`
0090 [ -z "$top" ] && top=0
0091 [ -z "$left" ] && left=0
0092 [ -z "$bottom" ] && bottom=0
0093 [ -z "$right" ] && right=0
0094 echo $recordtitle $scale $top $left $bottom $right >> $record
0095 rm -f $tmp