SVG
SVG copied to clipboard
Nested Images in SVG not been converted when exported to PNG on Linux
I have an SVG file shown in the text below the Image elements inside nested SVG's work but images do not:
This renders when converting from SVG to PNG:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" class="draggable" x="38.21985345113531" y="154.94029490697463" width="60" height="60" id="svgHomePlayer1_1" name="svgHomePlayer1_1"><image x="0" y="10" width="50" height="50" xlink:href="dee971bc-2de8-411f-9bef-41b16ec34eb8.svg" id="imageHomePlayer1_1" name="imageHomePlayer1"></image><text x="1" y="8" width="59" height="59" font-size="12" fill="#000000" font-weight="bold" id="imageaHomePlayer1_1" name="imageaHomePlayer1">Goalkeeper</text><text x="19" y="40" font-size="20" fill="#000000" font-weight="bold" id="imagenumHomePlayer1_1" name="imagenumHomePlayer1">1</text></svg>
This does not:
<image x="86.04182371920514" y="168.71950667913035" width="50" height="50" xlink:href="ball.svg" class="draggable" id="shape1"></image>
both of the above are inside a big svg like this:
<svg height="800" width="420" id="svgFrame1" style="border: 0px dashed red;margin-right:3px;float:left;" onclick="selectFrame(1)" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 800 420"></svg>
For the above image I get a white circle (correct size) but not a ball as expected
It works fine on Windows 10 but not on Ubuntu / Linux
Version 3.1 / latest of the Nuget Package
.net core 2.1 website
Code to generate the PNG:
var svgDocument = Svg.SvgDocument.Open("myFile.svg"); svgDocument.Width = new Svg.SvgUnit(800); svgDocument.Height = new Svg.SvgUnit(420); var bm = svgDocument.Draw();
bm.Save("output.png", System.Drawing.Imaging.ImageFormat.Png);
Thanks in advance
Not sure if related, but only one of the SvgDocument overloads for Open and FromSvg reads the
var svgXml = new XmlDocument();
svgXml.LoadXml(svgTemplate); // svgTemplate is an svg string generated by me
svgXml.Save("faszomsvg.svg");
//var svgDocument = SvgDocument.Open("test.svg");
//var svgDocument = SvgDocument.Open(svgXml);
//var svgDocument = SvgDocument.FromSvg<SvgDocument>(svgTemplate);
//var svgDocument = SvgDocument.Open<SvgDocument>(new MemoryStream(Encoding.UTF8.GetBytes(svgTemplate)));
var svgDocument = SvgDocument.Open("faszomsvg.svg"); // ONLY THIS WORKS
Update: This one is actually caused by my embedded images being simply relative paths, right next to my executable from where the svg lib is also executed. Looking at the source, I found that when giving a file path, the SvgDocument.BaseUri is set based on the file path, but it is not correctly set when you just have a stream. The SvgImage tries to guess the BaseUri, but only works for http: and file: protocols, so the trick in my case was this. I don't clearly see your example, but maybe same applies?