question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Icons not included into the resulting svg and as a result can not be imported into the SaaS such as draw.io

See original GitHub issue

Icons not included into the resulting svg and as a result can not be imported into the SaaS such as draw.io

Hi, thanks, cool project, I was following guides and created example and changed outformat="svg"

However svg generated contains following:

<g id="node5" class="node">
<title>3f42a5b2346adbddd04f3b60e84ea285</title>
<image xlink:href="/Users/test/.local/share/virtualenvs/diag-AzfPdfmQ/lib/python3.7/site-packages/resources/aws/compute/elastic-container-service.png" width="101px" height="101px" preserveAspectRatio="xMinYMin meet" x="310" y="-470.5"/>
<text text-anchor="middle" x="360.5" y="-358.1" font-family="Sans-Serif" font-size="13.00" fill="#2d3436">web3</text>
</g>

I.e. it references icons from filesystem, as a result, when I try to upload this svg to SaaS such as draw.io it results in image being rendered without icons, i.e.

image

Is there any way to embed icons in the resulting SVG?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:7
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
staticalandcommented, May 23, 2020

@atkawa7 Thanks! scour works well for me with this code:

from scour import scour
from diagrams import Diagram
from diagrams.aws.compute import EC2

filename = "ec2"
outformat = "svg"
full_filename = f"{filename}.{outformat}"

with Diagram("EC2", filename=filename, show=False, direction="LR", outformat=outformat, graph_attr={"pad": "0.1,0.1"}):
    EC2()

with open(full_filename, "r") as f:

    in_string = f.read()
    out_string = scour.scourString(in_string)

with open(full_filename, "w") as f:

    f.write(out_string)

This embeds the images as base64 in the XML of the SVG file. Of course a better solution would be to intercept the SVG before it’s saved to disk.

So instead of running self.dot.render(format=self.outformat, view=self.show) on the SVG, maybe do something like scour.scourString(self.dot.pipe().decode('utf-8')) and write that to file. What do you think @mingrammer?

See https://graphviz.readthedocs.io/en/stable/manual.html#piped-output

Function in scour is embedRasters.

Used like:

for elem in doc.documentElement.getElementsByTagName('image'):
    embedRasters(elem, options)
2reactions
skgsergiocommented, Mar 8, 2022

Less ugly patch than the one mentioned by @ajeep8:

with Diagram("My Diagram", show=False, outformat="svg", graph_attr={"bgcolor": "white"}) as diag:
    # Use graphviz cairo renderer to force image embedding
    diag.dot.renderer = "cairo"

"bgcolor": "white" is important if you want a solid white background as using cairo defaults to transparent.

The downside is that it will name your file my_diagram.cairo.svg

Read more comments on GitHub >

github_iconTop Results From Across the Web

Insert SVG images into a diagram
Once the SVG image is added to the drawing canvas as a shape, you can resize it. Note: You cannot import an SVG...
Read more >
Blog - Diagrams.net
You can draw Azure architecture diagrams for your cloud infrastructure from scratch, or import .vsdx files or exported diagrams from automated infrastructure ...
Read more >
Draw.io Import does not preserve labels - Lucidchart Help
I am trying to import my draw.io charts into Lucidchart. I tried a simple example, but the resulting chart in Lucid does not...
Read more >
Untitled
Browse The Most Popular 1 Github Markdown Integration Drawio Open Source Projects ... and results in proper colours when breaks are not equally...
Read more >
Inkscape "Viewer does not support full SVG 1.1"
Why is this being imported into Inkscape, instead of finishing in diagrams.net? ... I had no idea draw.io svg was universally incompatible.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found