Ok so this script requires the "netpbm" package of image
manipulation programs. Anyone who builds Lilypond from source
probably has it already, but it's easy to get under Linux and Mac.
for Ubuntu I do "sudo apt-get install netpbm" and for mac "sudo
port install netpbm". I see that there's a Windows version but
I've never tried to install that because I rarely use Windows. So
far the script works perfectly for Linux and Mac OSX 10.4 (maybe
10.5 but I can't try it b/c I don't have one). A couple of lines
are different in the Mac version because of the different image
viewer and different way of invoking lilypond at the command line.
What I find useful about the script is that it prompts the user for
the desired output resolution and format. So far I've run it
successfully at resolutions from 72 to 1200 dpi in png, jpeg, and
tiff formats. I suppose you could use any image format for which
there is a "pnmto___" program, substituting the appropriate text
for the format. The script will look for whatever format you type
in there.
Note, if you want a musical example suitable for inserting in a
word-processed doc or web page, you might want to remove or comment
out the header block of your file.
Once you've saved and made the file executable (I keep it in my /
bin directory so it's in my $PATH), just do "lilyimage foobar.ly"
and enter the resolution and format when prompted.
I copy below the Linux and Mac versions. It would be cool if
someone made it work on Windows, to :)
Linux version of "lilyimage" script
#!/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
# ask for desired final output format
echo -n "Enter desired output format (jpeg, png, tiff): "
# gather format input
read FORMAT
cd $OUTDIR
# run lilypond on file with png output for further processing...
lilypond --format=png -dresolution=$RES $srcfile
# The next commands crop the png file so that
# it only includes the example instead of an entire page.
# First convert image to pnm for processing with netpbm tools
pngtopnm $STEM.png > $STEM.pnm
# crop all the white space off
pnmcrop -white $STEM.pnm > $STEM-cropped.pnm
# convert to end format
pnmto$FORMAT $STEM-cropped.pnm > $STEM.$FORMAT
# removes pnm and ps files
rm *.pnm $STEM.ps
# open final image as background process in "Eye of Gnome" Image
Viewer
eog $STEM.$FORMAT &
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Mac version of script:
#!/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
# ask for desired final output format
echo -n "Enter desired output format (jpeg, png, tiff): "
# gather format input
read FORMAT
cd $OUTDIR
# run lilypond on file with png output for further processing...
/Applications/LilyPond.app/Contents/Resources/bin/lilypond --
format=png -dresolution=$RES $srcfile
# The next commands crop the png file so that
# it only includes the example instead of an entire page.
# First convert image to pnm for processing with netpbm tools
pngtopnm $STEM.png > $STEM.pnm
# crop all the white space off
pnmcrop -white $STEM.pnm > $STEM-cropped.pnm
# convert to end format
pnmto$FORMAT $STEM-cropped.pnm > $STEM.$FORMAT
# removes pnm and ps files
rm *.pnm $STEM.ps
# open final image as background process in "Eye of Gnome" Image
Viewer
open -a preview $STEM.$FORMAT
Graham Percival wrote:
On Tue, 19 Aug 2008 14:41:24 +0000
David Bobroff <address@hidden> wrote:
I'm LilyPonding a piece which requires a "Notation Key". The
recipient of this notation key will be doing a bit of further
manipulation of the output. What I need to provide is, at her
preference, a PNG closely cropped so that she can then position
this
graphic under some introductory text about the piece. I have been
unsuccessful at finding information about this in the docs.
If it's a single line of music,
-dpreview
could do the job. (that's what I use)
The info in AU about lilypond-book might help (inserting lilypond
output into other program), but probably won't, since it's aimed
at producing eps images. Actually, you might be able to convert
the eps to png using an external program.
Finally, you could play with clip-example, which I believe is now
in NR 3. But I'm not certain if anybody's rewritten the docs for
them -- I certainly haven't.
Cheers,
- Graham
_______________________________________________
lilypond-user mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/lilypond-user