lilypond-user
[Top][All Lists]
Advanced

[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 <valentin@petzel.at> 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: https://stackoverflow.com/questions/30582159/avoiding-rasterization-with-svg-image-so-that-transforms-work-in-firefox.
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):

http://www.jameselkins.com/pianofiles/wp-content/uploads/2014/10/Screen-Shot-2014-10-29-at-11.11.39-AM-1024x653.jpg

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:

https://github.com/Klowner/inkscape-applytransforms

Here is my (alfa) procedure:

1) create a snippet and save it as snippet.ly. 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: snippet-to-markup.ly). I created a "svg-paths-to-ly-paths.py" script for this job:

python3 svg-paths-to-ly-paths.py snippet-paths-only.svg snippet-to-markup.ly

4) compile snippet-to-markup.ly 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.

Best,
P



Attachment: snippet.ly
Description: Text Data

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

Attachment: snippet.svg
Description: image/svg

Attachment: snippet-to-markup.ly
Description: Text Data


reply via email to

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