#!/bin/bash #*****************************************************# # Script for making image files from lilypond source # # suitable for use as musical examples to insert in a # # document or web page. # #*****************************************************# # get filename from first argument srcfile="`basename $1`" # get filename without .ly extension STEM="`basename $1 .ly`" # determine output directory OUTDIR="`dirname $1`" # ask for output resolution echo -n "Enter output resolution in DPI (72, 100, 300, 600, etc.): " # gather resolution input read RES echo "Resolution is set to $RES" echo -n "Would you like a transparent background? (y/N): " read TRANSPARENCY if [[ ( "$TRANSPARENCY" == "yes" ) || ( "$TRANSPARENCY" == "y" ) || ( "$TRANSPARENCY" == "Y" )]] then echo "Background is set to transparent" echo -n "Enter desired output format (png or gif): " read TRANSFORMAT echo "Output format is set to $TRANSFORMAT" cd $OUTDIR lilypond --format=png -dresolution=$RES $srcfile pngtopnm $STEM.png > $STEM.pnm pnmcrop -white $STEM.pnm > $STEM-cropped.pnm if [ "$TRANSFORMAT" == "png" ] then pnmto$TRANSFORMAT -transparent '#ffffff' $STEM-cropped.pnm > $STEM.$TRANSFORMAT else ppmto$TRANSFORMAT -transparent '#ffffff' $STEM-cropped.pnm > $STEM.$TRANSFORMAT fi eog $STEM.$TRANSFORMAT & else # ask for desired final output format echo -n "Enter desired output format (jpeg, png, tiff, gif, pcx, bmp, pgm): " # gather format input read FORMAT echo "Output format is set to $FORMAT" cd $OUTDIR lilypond --format=png -dresolution=$RES $srcfile pngtopnm $STEM.png > $STEM.pnm pnmcrop -white $STEM.pnm > $STEM-cropped.pnm if [[ ( "$FORMAT" == "tiff" ) || ( "$FORMAT" == "png" ) ]] then pnmto$FORMAT $STEM-cropped.pnm > $STEM.$FORMAT else ppmto$FORMAT $STEM-cropped.pnm > $STEM.$FORMAT fi # open final image as background process in "Eye of Gnome" Image Viewer eog $STEM.$FORMAT & fi # removes pnm and ps files rm *.pnm $STEM.ps