lilypond-user
[Top][All Lists]
Advanced

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

Re: png cropping


From: Patrick Horgan
Subject: Re: png cropping
Date: Wed, 17 Sep 2008 17:10:46 -0700
User-agent: Thunderbird 2.0.0.16 (X11/20080724)

Here's a modified version of Jonathan's unix/linux script that supports arguments which are:

-t or --transparency         :  output format forced to png and you get 
transparency

-r=N or --resolution==N      : (example -r=72) set resolution

-f=FORMAT or --format=FORMAT : (example -f=jpeg) set output format


So, if the script is named lilytoimage, you could do:

lilytoimage -r=72 -t lilydir/myfile.ly

or

lilytoimage -r=111 -f=tiff lilydir/myfile.ly


If you don't specify any of those arguments then it works just like it did before, except it will also ask about transparency. I don't have a Mac to test on, so I didn't mess with the Mac version. Let me know if there's any bugs;)

Patrick

~~~~8< cut here >8~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#!/bin/bash

#*****************************************************#

# Script for making image files from lilypond source  #

# suitable for use as musical examples to insert in a #

# document or web page.                               #

#*****************************************************#


getopt_simple()

{

   until [ -z "$1" ] ; do

       if [ ${1:0:1} = '-' ] ; then

           tmp=${1:1}               # Strip off leading '-' . . .

           if [ ${tmp:0:1} = '-' ] ; then

               tmp=${tmp:1}         # Allow double -

           fi

           parameter=${tmp%%=*}     # Extract name.

           value=${tmp##*=}         # Extract value.

           eval $parameter=$value

       else

           filename=$1

       fi

       shift

   done

}


transparency='no'

t='no'

resolution=0

r=0

format='none'

f='none'


getopt_simple $*

if [ $t != 'no' ] ; then

   transparency=$t

fi

if [ $r -ne 0 ] ; then

   resolution=$r

fi

if [ $f != 'none' ] ; then

   format=$f

fi

# get filename from first argument

srcfile="`basename $filename`"


# get filename without .ly extension

STEM="`basename $filename .ly`"


# determine output directory

OUTDIR="`dirname $filename`"


if [[ $resolution -ne 0 ]] ; then

   echo Resolution set to $resolution dots per inch.

   RES=$resolution

else

   # ask for output resolution

   echo -n "Enter output resolution in DPI (72, 100, 300, 600, etc.): "

   # gather resolution input

   read RES

fi


# ask for desired final output format

if [[ $transparency != 'no' ]] ; then

   echo Output format forced to png for transparency

   FORMAT='png'

else

   echo -n "Transparency?y/N "

   #gather transparency

   read TRANSPARENCY

   echo TRANSPARENCY is $TRANSPARENCY

   if [[ ( "$TRANSPARENCY" == "Y" )  || ( "$TRANSPARENCY" == "y" ) ]] ; then

       transparency='yes'

       echo Output format forced to png for transparency

       FORMAT='png'

   else

       if [[ $format != 'none' ]]

           echo Output format is $format

           FORMAT=$format

       else

           echo -n "Enter desired output format (jpeg, png, tiff): "

           # gather format input

           read FORMAT

       fi

   fi

fi


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

if [[ $transparency != 'no' ]] ; then

   pnmto$FORMAT -transparent '#ffffff' $STEM-cropped.pnm > $STEM.$FORMAT

else

   pnmto$FORMAT $STEM-cropped.pnm > $STEM.$FORMAT

fi


# removes pnm and ps files

rm *.pnm $STEM.ps


# open final image as background process in "Eye of Gnome" Image Viewer

eog $STEM.$FORMAT &

fi


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

if [[ $transparency != 'no' ]] ; then

   pnmto$FORMAT -transparent '#ffffff' $STEM-cropped.pnm > $STEM.$FORMAT

else

   pnmto$FORMAT $STEM-cropped.pnm > $STEM.$FORMAT

fi


# removes pnm and ps files

rm *.pnm $STEM.ps


# open final image as background process in "Eye of Gnome" Image Viewer

eog $STEM.$FORMAT &

fi


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

if [[ $transparency != 'no' ]] ; then

   pnmto$FORMAT -transparent '#ffffff' $STEM-cropped.pnm > $STEM.$FORMAT

else

   pnmto$FORMAT $STEM-cropped.pnm > $STEM.$FORMAT

fi


# removes pnm and ps files

rm *.pnm $STEM.ps


# open final image as background process in "Eye of Gnome" Image Viewer

eog $STEM.$FORMAT &

~~~~8< cut here >8~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





reply via email to

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