]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/ps-to-gifs.sh
e2a3da89cb7b0451cd3d55a9610557f32bcfbc43
[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   -s, --size=SIZE    set papersize
15   -t, --transparent  change white to transparent
16 EOF
17 }
18
19 if [ $# -lt 1 ]; then
20     usage;
21     exit 2;
22 fi
23 CROP=cat
24 GIF=gif
25 PNMTOGIF=ppmtogif
26
27 while [ $# -gt 0 ]; do
28 opt=$1
29 shift
30     case $opt in
31     -t|--t*)
32         color='-transparent white'
33         ;;
34     -h|--h*)
35         usage;
36         exit 0
37         ;;
38     -c|--c*)
39         CROP=" pnmcrop "
40         ;;
41     -o) OUTFILE=$2; shift
42         ;;
43     --o*=*) OUTFILE=`echo $opt | sed -e s/"^.*="//`
44         ;;
45     -p|--p*)
46         GIF=png
47         PNMTOGIF=pnmtopng
48         ;;
49     -s) SIZE="-sPAPERSIZE=$2"; shift
50         ;;
51     --s*=*)
52         SIZE="-sPAPERSIZE=`echo $opt | sed -e s/"^.*="//`"
53         ;;
54     -*)
55         echo "ps-to-gifs: unknown option: \`$opt'"
56         exit 1
57         ;;
58     *)
59         FILE=$opt
60         ;;
61     esac
62 done
63
64 if [ "x$TRANSPARENT_IS_BROKEN" != "x" ]; then
65         color=
66 fi
67
68 if [ "x$OUTFILE" = "x" ]; then
69         BASE=`dirname $FILE`/`basename $FILE .ps`
70 else
71         BASE=`dirname $OUTFILE`/`basename $OUTFILE .$GIF`
72 fi
73
74 # urg, pipe breaks
75 rm -f $BASE{.ppm,.$GIF} $BASE-page*{.ppm,.$GIF}
76
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
86
87 if [ "x$OUTFILE" != "x" ]; then
88         mv $BASE-page1.$GIF $BASE.$GIF
89 fi
90