lilypond-1.3.122
[lilypond.git] / buildscripts / ps-to-gifs.sh
blobe2a3da89cb7b0451cd3d55a9610557f32bcfbc43
1 #!/bin/sh
2 # ps-to-gifs, convert PS to multiple gifs or other bitmaps
4 usage()
6 cat <<EOF
7 Convert PS to multiple gifs or other bitmaps
8 Usage: ps-to-gifs.sh [OPTION]... [FILE]
9 Options:
10 -h, --help this help
11 -c, --crop crop output
12 -o, --output=NAME set output base
13 -p, --png convert to png
14 -s, --size=SIZE set papersize
15 -t, --transparent change white to transparent
16 EOF
19 if [ $# -lt 1 ]; then
20 usage;
21 exit 2;
23 CROP=cat
24 GIF=gif
25 PNMTOGIF=ppmtogif
27 while [ $# -gt 0 ]; do
28 opt=$1
29 shift
30 case $opt in
31 -t|--t*)
32 color='-transparent white'
34 -h|--h*)
35 usage;
36 exit 0
38 -c|--c*)
39 CROP=" pnmcrop "
41 -o) OUTFILE=$2; shift
43 --o*=*) OUTFILE=`echo $opt | sed -e s/"^.*="//`
45 -p|--p*)
46 GIF=png
47 PNMTOGIF=pnmtopng
49 -s) SIZE="-sPAPERSIZE=$2"; shift
51 --s*=*)
52 SIZE="-sPAPERSIZE=`echo $opt | sed -e s/"^.*="//`"
54 -*)
55 echo "ps-to-gifs: unknown option: \`$opt'"
56 exit 1
59 FILE=$opt
61 esac
62 done
64 if [ "x$TRANSPARENT_IS_BROKEN" != "x" ]; then
65 color=
68 if [ "x$OUTFILE" = "x" ]; then
69 BASE=`dirname $FILE`/`basename $FILE .ps`
70 else
71 BASE=`dirname $OUTFILE`/`basename $OUTFILE .$GIF`
74 # urg, pipe breaks
75 rm -f $BASE{.ppm,.$GIF} $BASE-page*{.ppm,.$GIF}
77 cat $FILE | gs -sDEVICE=pgm $SIZE -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="$BASE-page%d.ppm" -r90 -dNOPAUSE - -c quit $FILE
78 # quant is soo slow
79 # cat $PPMFILE | ppmquant 2 | pnmscale 0.3333 | pnmcrop | $PNMTOGIF $color > $OUTFILE
80 PPMS=`ls $BASE*ppm`
81 for i in $PPMS; do
82 o=`dirname $i`/`basename $i .ppm`.$GIF
83 cat $i | $CROP | $PNMTOGIF $color > $o
84 rm $i
85 done
87 if [ "x$OUTFILE" != "x" ]; then
88 mv $BASE-page1.$GIF $BASE.$GIF