lilypond-1.1.44
[lilypond.git] / buildscripts / ps-to-gifs.sh
blob0f4afe0a5ab7177bd0a7916f0e681687fc697f60
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 # generate the pixmap at twice the size, then rescale (for antialiasing)
78 cat $FILE | gs -sDEVICE=ppmraw $SIZE -sOutputFile="$BASE-page%d.ppm" -r180 -dNOPAUSE - -c quit $FILE
79 # quant is soo slow
80 # cat $PPMFILE | ppmquant 2 | pnmscale 0.3333 | pnmcrop | $PNMTOGIF $color > $OUTFILE
81 PPMS=`ls $BASE*ppm`
82 for i in $PPMS; do
83 o=`dirname $i`/`basename $i .ppm`.$GIF
84 cat $i | pnmscale 0.5 | $CROP | $PNMTOGIF $color > $o
85 rm $i
86 done
88 if [ "x$OUTFILE" != "x" ]; then
89 mv $BASE-page1.$GIF $BASE.$GIF