13

I have an SVG file that references lots of other, smaller, SVGs as sub images. Effectively, the main SVG is the template that positions all the other ones.

I'd like to create a single image that I can pass on to people - i.e. a data ref or just inline inclusion - but running the inkscape Embed Images extension results in the error "images are not of type PNG, JPEG, etc".

So it sounds like the inkscape (v0.48.5) extension can only intern bitmap images, not SVGs. Bummer.

My images are referenced from the master SVG like this

<image id="PGDOWN_R1" x="1436.5"  y="280"  xlink:href="./symbols/PGDOWN_R3.svg"/>

So how can I automatically intern/embed all my externally referenced SVGs? (non-inkscape CLI options are welcome too)

Community
  • 1
  • 1
fommil
  • 5,757
  • 8
  • 41
  • 81
  • I reckon one could probably write a script that would do the embedding without too much trouble, but I don't see a way to do it with Inkscape. – Duncan Thacker Jun 21 '15 at 21:34
  • well, scripting it is always the fallback, but I'd like to know if there is something that can already do this. Surely people use DRY in SVG, right? How can you reuse components between files unless you reference them externally? – fommil Jun 21 '15 at 21:35
  • I thought this might be a duplicate of [Merging multiple SVG files into one](http://stackoverflow.com/questions/14562136/merging-multiple-svg-files-into-one) but it's not. – fommil Jun 21 '15 at 21:48
  • @Harry I'm wondering if there is an **existing** programming tool to achieve this. And, btw, inkscape **is** a programming tool (it has a CLI) and I should therefore propose that this is on-topic regardless of the approach taken. – fommil Jun 22 '15 at 08:02
  • This answer has a hacky but functional Perl script that embeds any linked images: https://stackoverflow.com/questions/46472054/how-can-i-change-http-linked-images-in-inkscape-0-92-to-embedded-ones – lambshaanxy Oct 01 '20 at 04:17

2 Answers2

4

At least as of Inkscape 0.91 you can do this through this menu:

ExtensionsImagesEmbed Images

Quite easily!

Valerio Bozz
  • 1,176
  • 16
  • 32
Jamie Pate
  • 1,783
  • 20
  • 18
  • 6
    This does not work on `svg` files though, at least for 0.91 r13725,as the script seems to only support pixel files (for svgs you get `[yoursvgfile].svg is not of type image/png, image/jpeg, image/bmp, image/gif, image/tiff, or image/x-icon`) – ted May 09 '18 at 19:33
  • 2
    This doesn't work on `SVG` images, so it does not answer the question. – Kresimir Oct 18 '19 at 04:15
-2

I ended up using xmllint to parse an SVG file with handles into a file containing the embedded versions of the referenced files, which is not exactly what I mean but it suited my purposes: https://gitlab.com/fommil/attic/blob/master/kinesis-dvorak/create.sh#L37

xmllint --xinclude picture.svg  > picture-embedded.svg
ted
  • 4,791
  • 5
  • 38
  • 84
fommil
  • 5,757
  • 8
  • 41
  • 81
  • I came across the same problem, unfortunately your link is broken. As the top rated answer does not work for embedding svg's I would be interested in the script, could you please fix the link? – ted May 09 '18 at 19:37
  • 1
    I updated it, but I think you misunderstand... `xmllint` is the tool I used. The referenced script is just how I used it. – fommil May 10 '18 at 13:41
  • 3
    I was hoping that your script would show me how to use `xmllint` to turn `svg_with_img_href.svg` into `standalone_everything_embedded.svg`. However, `xmllint --xinclude svg_with_img_href.svg > standalone.svg` does not work for me. – ted May 11 '18 at 16:38