My question concerns the creation of images using lilypond. Until know I've created some music sheets and lilypond has been really great. However I have a website and I would like to post some examples to illustrate what I'm saying. The images should just fit the size of what is written. It will mostly been 2-3 bars max, but I would like the size to fit automatically as it could be bigger.

When I use the --png option, it creates an image the size of an A4 page. I tried using the snippets shown in the doc, for exemple here : http://lilypond.org/doc/v2.12/input/lsr/12/lily-1ed76b9d.ly

If I comment the \include "lilypond-book-preamble.ly", then it shows as an A4 document. If I leave it, then I'm asked to add -dbackend=eps to the command line. If I add it, then it actually produces the result i'm searching for. However it also adds a whole bunch of files (multiple .pdf, .eps, .tex, .texi, .count).

Is there a proper way to do it, or should I write a bash script to clean the folder after the lilypond command?

Another thing: with the --png option, are we able to define an image size? I'm able to change it using -dresolution but it's not very handy as you have to try to see the output size, then change and try again... Maybe is it better to create .pdf and use other scripts to convert into .png?

Thank you in advance! I searched for this information but found very little about it so far...

  • 2
    Note that your link is to the documentation for the v2.12 version of the software. You may want to consider using a newer version, or looking at the documentation for the version that you are using.
    – Dave
    Commented Feb 17, 2014 at 20:18
  • Note that cross posting the same question on multiple sites is frowned upon, c.f. (meta.stackexchange.com/questions/64068/…)
    – Dave
    Commented Feb 17, 2014 at 20:21
  • Sorry, i'm new here. I read several posts that said lilypond questions could belong in both, not that it was limited to one. Won't happen again. I also updated my lilypond version (the one in the depository is deprecated).
    – Fnor
    Commented Feb 18, 2014 at 1:59
  • Related: superuser.com/questions/96970/… Commented Oct 21, 2019 at 0:34

2 Answers 2


I use the following as my header (since version 2.16):

    bookTitleMarkup = ##f
    scoreTitleMarkup = ##f
    \relative c' { c4 d e f | g a b c }

and compile it using lilypond -dbackend=eps -dno-gs-load-fonts -dinclude-eps-fonts --png test.ly. The resulting png files fit to the music. This does produce the extraneous (mostly TeX related) files; I do not know of a way around that.

  • Thanks, this gives me the expected result! However it also gives a lot of files I won't use (.eps, .tex, ...). Is there a way to handle it with lilypond or am I better off using rm?
    – Fnor
    Commented Feb 18, 2014 at 2:04
  • @Fnor Combing the documentation reveals the -ddelete-intermediate-files flag. Does this do what you want? Failing that, you could always wrap lilypond in a shell script that copies the file to a temporary directory renders it, copies the result back, and deletes temporary directory again. Commented Oct 21, 2019 at 10:32

I would add to Dave's answer that if you want to have everything in a single system and you don't want to care about the width and height settings, you could just put

page-breaking = #ly:one-line-breaking

into your \paper block. That will cause the width and height settings to be ignored and all of the music typeset in a single system, with no whitespace at the borders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.