]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/ps-to-gifs.sh
patch::: 1.0.8.jcn3: png
[lilypond.git] / buildscripts / ps-to-gifs.sh
1 #!/bin/sh
2 # ps-to-gifs, convert PS to multiple gifs or other bitmaps
3
4 usage()
5 {
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   -t, --transparent  change white to transparent
15 EOF
16 }
17
18 if [ $# -lt 1 ]; then
19     usage;
20     exit 2;
21 fi
22 CROP=cat
23 GIF=gif
24 PNMTOGIF=ppmtogif
25
26 while [ $# -gt 0 ]; do
27 opt=$1
28 shift
29     case $opt in
30     -t|--t*)
31         color='-transparent white'
32         ;;
33     -h|--h*)
34         usage;
35         exit 0
36         ;;
37     -c|--c*)
38         CROP=" pnmcrop "
39         ;;
40     -o) OUTFILE=$2; shift
41         ;;
42     --o*=*) OUTFILE=`echo $opt | sed -e s/"^.*="//`
43         ;;
44     -p|--p*)
45         GIF=png
46         PNMTOGIF=pnmtopng
47         ;;
48     -*)
49         echo "ps-to-gifs: unknown option: \`$opt'"
50         exit 1
51         ;;
52     *)
53         FILE=$opt
54         ;;
55     esac
56 done
57
58 if [ "x$TRANSPARENT_IS_BROKEN" != "x" ]; then
59         color=
60 fi
61
62 if [ "x$OUTFILE" = "x" ]; then
63         BASE=`dirname $FILE`/`basename $FILE .ps`
64 else
65         BASE=`dirname $OUTFILE`/`basename $OUTFILE .$GIF`
66 fi
67
68 # urg, pipe breaks
69 rm -f $BASE{.ppm,.$GIF} $BASE-page*{.ppm,.$GIF}
70
71 # generate the pixmap at twice the size, then rescale (for antialiasing)
72 cat $FILE | gs -sDEVICE=ppmraw -sOutputFile="$BASE-page%d.ppm" -r200 -dNOPAUSE - -c quit $FILE
73 # quant is soo slow
74 # cat $PPMFILE | ppmquant 2 | pnmscale 0.3333 | pnmcrop | $PNMTOGIF $color > $OUTFILE
75 PPMS=`ls $BASE*ppm`
76 for i in $PPMS; do
77     o=`dirname $i`/`basename $i .ppm`.$GIF
78     cat $i | pnmscale 0.5 | $CROP | $PNMTOGIF $color > $o
79     rm $i
80 done
81
82 if [ "x$OUTFILE" != "x" ]; then
83         mv $BASE-page1.$GIF $BASE.$GIF
84 fi
85