Cool, Patrick! Your scripting skills are admirable! The only thing
that worked unlike I expected was when I was asked if I wanted
transparency, I simply hit "enter," thinking it would default to "no"
because the N was capitalized, and it prompted me again saying
"expecting one of these values..." On my script the enter button worked
for "no." Not a big deal.
The way I dealt with the lack of ppmtopng or ppmtotiff was to add
another "if" statement that called on pnmtopng or pnmtotiff if either
png or tiff were chosen for the output format. Probably not very
elegant or flexible, but the only way I know how to deal with it at the
moment. Did you see the latest version? I think you were commenting on
an earlier version that was broken with png and tiff. It's hard to keep
track when I keep posting so many :)
I'm going to study your script carefully when I have more time tonight
and try it with the command-line options and stuff. It's shaping up to
be a very useful tool, at least for me :) Thanks for being so interested
in it and scripting all these cool features that I don't know how to do.
Jon
(My working version is attached)
Patrick Horgan wrote:
Jonathan Kulp wrote:
Ok I changed a couple of things to make it even more flexible. I changed
pnmto__ to ppmto__, giving quite a few more output options. I've suggested a
few in the script. Also added an option to choose either gif or png when
choosing transparent background. this is fun :)
Jonathan, on my system there's no ppmtopng or ppmtotiff and ppmtojpeg is a link
to pnmtojpeg. This is with Hardy Ubuntu and a fresh install of the utils.
Annoying, no? It makes the changes to your script break on my machine.
I've found that creating symbolic links in /usr/bin like:
ln -s pnmtopng ppmtopng
ln -s pnmtotiff ppmtotiff
fixes the problem, but why wouldn't that have been done automagically? I
removed the netpbm package and it didn't remove my links, so they're really not
part of the package. Maybe I should file a bug against the package. It does
reinstall the link from ppmtojpeg to pnmtojpeg when I reinstall it. How is it
set up on your system?
It seems like to be bulletproof, the script needs to check and see which of
ppmto$FORMAT and pnmto$FORMAT exists and use that, that's easy to do with which,
it already has all the code to look through your PATH.
I'm attaching a new version of my version of your script with that change and a
new routine, getval, that validates input, you use it like:
prompt= "Enter desired output format (jpeg, png, tiff, gif, pcx, bmp): "
goodvals=("jpeg" "png" "tiff" "gif" "pcx" "bmp")
getval
FORMAT=$outval
If the user enters something that's not on the goodvals list, for example joe,
it reprompts them after telling them what they might have entered:
Enter desired output format (jpeg, png, tiff, gif, pcx, bmp): joe
Expecting one of : jpeg png tiff gif pcx bmp
Enter desired output format (jpeg, png, tiff, gif, pcx, bmp):
Cool, no? I suppose I should add validation to the command line arguments as
well.
Ok, just did that, resolution checked for numeric both on input and from the
command line, format checked for one of the allowable things, and check to make
sure there's a filename, and print meaningful error message and a usage
statement. Try it and see if it works for you.
I'm almost tempted to check for all the pnmto and ppmto and automatically
build the list of allowed types instead of hard coding them--nah, I'll leave
that as an exercise for the reader;) It really needs to be done with my version
because I only let people use what's on the list:( Yours will just work as long
as it's a valid format. You could grab the outcmd part of my version of your
script. It automagically picks either ppmto or pnmto and exits with an error if
neither are found.
I also check for the existence of pnmtojpeg and abort the script if not
found with
a message that the netpbm utilities have to be installed to use the script.
Now the script is /much/ larger because of all the checking.
Patrick
Jon
script attached this time...
Patrick Horgan wrote:
Jonathan Kulp wrote:
I'm guessing that one of the netpbm tools will handle transparency, it's
just a matter of figuring out which one. Didn't this come up on a recent
thread? I seem to remember trying it out on something and getting a
transparent background. When I get some time later I'll 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:)
--
Jonathan Kulp
http://www.jonathankulp.com
#!/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