Patrick,

Sorry to keep posting new versions but I found another problem with my previous one, which is that there's no ppmtopng command, so I had to add another if-then statement to fix it. I also learned a couple of things from your script that are very useful (e.g. accepting equally "yes," "Y" or "y") and changed the prompt to a more usual style: from (yes/no) to (y/N).

I've now tried all variations and they all work. Now if you can integrate your mods to accept arguments at the command line that'd be sweet. Thanks for being interested in this :)

Jon

script:

#!/bin/bash

# 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


#!/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


_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to