[Top][All Lists]

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

Re: Embedding images into a score created with -dbackend=svg

From: Paolo Prete
Subject: Re: Embedding images into a score created with -dbackend=svg
Date: Sat, 27 Nov 2021 03:35:39 +0100

On Fri, Nov 26, 2021 at 7:18 PM Valentin Petzel <> wrote:
Hello Paolo,

I’m not exactly sure what you mean by „inline-svg”. The discussion you linked
to is about manually converting svg paths into lilypond paths. While this is
possible it surely would get very complicated with more advanced svg.

But it should be quite easy to use the <image>-tag svg gives us by it’s
specifications to embed any sort of jpeg, png or svg image.

Hello Valentin,

using the <image> tag has one big disadvantage, at least in my case, AFAIK: it can easily happen that the embedded image is automatically rasterized by the viewer. See:
In addition: how would I create the <image> tag with Lilypond? If I have to do manipulation on the svg file after it is created by LilyPond, then I would prefer inline svg, which means: nesting a <svg> tree inside another <svg> tree (<svg>...<svg></svg>...</svg>). Then I would avoid rasterization (and I would not have clashing ids, AFAIK). But I still prefer to do all on the LilyPond side, not after the output is created.
Let's consider my specific case. I have to put some measures with few notes as examples on the initial pages of the score. Something like this (+ staff lines and clefs):

I think the best solution is to convert svg paths to LP paths. I just found a very useful tool for Inkscape, which transforms SVG paths in a way that can be quite easily converted to LP paths:

Here is my (alfa) procedure:

1) create a snippet and save it as Compile it with SVG backend (output file: snippet.svg) 
2) process snippet.svg with CLI of Inkscape (with the Klowner transform filter), so to convert all the objects to path (output file: snippet-paths-only, tested on Linux, Inkscape 1.1)

inkscape --batch-process --actions="select-all;ObjectFlipVertically;object-to-path;select-all:all;com.klowner.filter.apply_transform.noprefs;export-filename:snippet-paths-only.svg;export-do" snippet.svg

3) feed a script which translates snippets-path-only.svg to LilyPond syntax (output file: I created a "" script for this job:

python3 snippet-paths-only.svg

4) compile with LP and voila.

First results are very promising, and I can already use this system for real cases. The size of the stems can be more accurate, but there's an easy fix for this: replacing the <rect> associated to the stem with a <line>, so to have a proper conversion of the object to a <path>. 

I attach to this message all the files of my test.


Description: Text Data

Attachment: snippet-paths-only.svg
Description: image/svg

Attachment: snippet.svg
Description: image/svg

Description: Text Data

reply via email to

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