lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: png cropping


From: Jonathan Kulp
Subject: Re: png cropping
Date: Wed, 17 Sep 2008 19:21:22 -0500
User-agent: Thunderbird 2.0.0.16 (X11/20080724)

Sorry, one more adjustment to the script. I found out that there's no ppmtotiff command, so I had to add another conditional to accommodate that. Seems to work with all combinations now:

#!/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 -n "Would you like a transparent background? (yes or no): "
read TRANSPARENCY

if [ "$TRANSPARENCY" == "yes" ]
  then
    echo -n "Enter desired output format (png or gif): "
    read TRANSFORMAT
    cd $OUTDIR
    lilypond --format=png -dresolution=$RES $srcfile
    pngtopnm $STEM.png > $STEM.pnm
    pnmcrop -white $STEM.pnm > $STEM-cropped.pnm
ppmto$TRANSFORMAT -transparent '#ffffff' $STEM-cropped.pnm > $STEM.$TRANSFORMAT
    eog $STEM.$TRANSFORMAT &

  else

    # ask for desired final output format
echo -n "Enter desired output format (jpeg, png, tiff, gif, pcx, bmp): "
    # gather format input
    read FORMAT

    cd $OUTDIR
    lilypond --format=png -dresolution=$RES $srcfile
    pngtopnm $STEM.png > $STEM.pnm
    pnmcrop -white $STEM.pnm > $STEM-cropped.pnm
      if [ "$FORMAT" == "tiff" ]
        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



Patrick Horgan wrote:
Jonathan Kulp wrote:
look into it. It would be simple enough to add a prompt asking if you'd like a transparent background, I guess.
Now that you mention it that rings a bell with me too! I'll have to search---

giftoppm foobar.gif | ppmtogif -transparent '#rgb' > fooquux.gif


works if you want gif. First translate to ppm, then translate back to gif with the -transparent flag specifying which color, (in this case #fff) will be transparent.

pnmtopng has the transparent argument, but pnmtotiff and jpeg don't since they don't support transparency...so, using your script, if you want transparency, you have to choose png for the output, then on the translation step from ppm just add the appropriate flags. I just tried it adding a quick -transparent '#ffffff' to the command line and then selecting png so it would work. It worked like a charm:)

Patrick


--
Jonathan Kulp
http://www.jonathankulp.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]