2

I am creating an svg file using python and its module svgwrite. Alongside with circles and so on (which works fine) I need to input another svg file. For that I used:

dwg = svgwrite.Drawing('test.svg', size=(size_x, size_y),  profile='tiny')
dwg.add(dwg.image('image.svg', insert=center_to_be, size=size_to_be))

It does what expected except for blurring the imported svg image. Well it is blurred when opened in inkscape. When I open it in chrome, it seems right, though I cannot zoom so much.

However, when I import the image using inkscape, it looks fine.

It seems to be independent on the svg image which is imported, works the same with all images I tried.

Am I doing something wrong? Or is it inkscape's bug? Is there another way how to include an svg to another svg in python considering that the imported svg is quite complicated and I only need to set its place and size in the resulting svg. I would really need the inkscape compatibility.

fales
  • 89
  • 7
  • 1
    If the output generated by Python is as you would expect it to be, you can rule out Python for sure, so you can reduce your question by that. Then, all that's left is that two programs display the graphic with different quality, and that's not a programming question. – Ulrich Eckhardt Mar 25 '18 at 08:07
  • I don't know `svgwrite`, but have you checked the result, whether it is actually including the respective SVG code or some rasterized version of it? – Sirko Mar 25 '18 at 08:12
  • Is the SVG file you're adding to the image small enough to post here as source? (If not, can you create a simple SVG image, and see if it still shows up the problem?) From [the looks of it, svgwrite just adds an `xlink` reference](https://github.com/mozman/svgwrite/blob/master/svgwrite/image.py), which I don't think should cause much of a problem, unless your source image is already something odd like raster data rather than pure SVG... – Matt Gibson Mar 25 '18 at 08:19
  • @ Ulrich Eckhardt: well the programing question is: How to do it differently to get it working. Thank you @ Sirko for the question. It seems that svgwrite creates some king of very complicated polygon while importing the svg through inkscape seems to import the individual commands from the previous svg (probably recomputed). So is there a way to do this in python simply enough? – fales Mar 25 '18 at 08:31
  • @ Matt Gibson: I tried e.g. this svg: [link](https://upload.wikimedia.org/wikipedia/commons/8/87/Worldmap_southern.svg) – fales Mar 25 '18 at 08:37
  • 1
    A lot will depend on the nature and content of the SVG files. especially the child one. Please post a [mcve]. – Paul LeBeau Mar 25 '18 at 09:15

1 Answers1

1

Inkscape doesn't have good support for SVG images embedded in SVG images. It shows them as their raster representations, see also https://bugs.launchpad.net/inkscape/+bug/171795 .

Moini
  • 1,239
  • 9
  • 10
  • Update: During the hackfest at Libre Graphics Meeting 2018, an option has been added to 'import' SVG images by linking them, just like it's possible with raster images (via GUI, not via editing in the XML editor), and a resolution can now be indicated for exporting/viewing the linked SVG file in Inkscape. This option will presumably be available in the next major Inkscape version. – Moini May 05 '18 at 23:41