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