8

I'me trying to use ImageMagick to convert SVG files to PNG.

The SVG file is as follows:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
    <image xlink:href="picture.jpg" width="200" height="200"/>
</svg>

No matter what method I use the final result doesn't include the image. Other SVG elements have rendered correctly.

I've tried:

convert test.svg test.png
rsvg-convert -o test.png test.svg

I've tried changing the image path to use file:///, absolute paths, remote urls, and url encoded variations of each. I've also formatted my file with and without a doctype.

I'm using librsvg 2.36.3 and ImageMagick 6.8.0-10 I have been able to use phantomjs to convert them but it seems like overkill for this one task.

Please help!

KTastrophy
  • 1,739
  • 15
  • 23
  • The image is missing X,Y coordinates. – Alvin K. May 23 '13 at 07:30
  • @AlvinK. The x,y coordinates are optional, they default to zero. – Erik Dahlström May 23 '13 at 08:41
  • @Erik: Thanks, I stand corrected. Have managed to convert barebones SVG with Doctype to PNG with ImageMagick 6.6.9-7 this morning. – Alvin K. May 23 '13 at 17:01
  • @AlvinK. did you include an image like I did above? – KTastrophy May 23 '13 at 17:41
  • @KTastrophy: exact copy + paste, only edit the jpg. The extra two lines are `` and `` - Have you tried using another JPG file? – Alvin K. May 23 '13 at 19:12
  • @AlvinK. I've tried that before. My DOCTYPE differed a bit but I just tried yours. Same result. What OS are you using? – KTastrophy May 23 '13 at 22:04
  • @KTastrophy: Ubuntu 12.04 - 64bit. Just wondering if the image is corrupted. Can you try using the verbose option with imagemagick, might give some useful info – Alvin K. May 26 '13 at 07:28
  • Did you manage to get it working @KTastrophy? – projeqht Aug 12 '13 at 20:06
  • @projeqht: Partially. I was able to get it to work only if the embedded image was a PNG. I haven't really been able to spend of enough time on it to find out why. Since then I've tried inkscape and had significantly better results which makes since since it is based on SVG. – KTastrophy Aug 12 '13 at 20:47
  • Strange... the Image I'm trying to embed IS a PNG but like you said, the image isn't rendered while the other SVG objects are. Actually, I can't even get a transparent background. If I remove the SVG image element, the background still renders white.. any ideas? – projeqht Aug 12 '13 at 21:05
  • Make sure you are using rsvg. `convert -list delegate` and make sure it says rsvg next to svg. What is the exact command you're trying? – KTastrophy Aug 14 '13 at 03:06
  • possible duplicate of [rsvg doesn't render linked images](http://stackoverflow.com/questions/2961624/rsvg-doesnt-render-linked-images) – Ian Mackinnon Apr 14 '15 at 16:27

1 Answers1

1

For me, installing gtk3 (or probably more specifically "shared-mime-info" helped. (and re-installing rsvg afterwards AND using absolute "file:///" uri for href AND having image file in same directory as svg file)

More info (I'm still confused what exactly is going on):

  • I think the problem is not with rsvg directly, but with gdk-pixbuf(2) library

  • I found the place in the code where gdk-pixbuf is used to load the image. I confirmed (using printf debuggin) that it doesn't throw an error (seems to load pixbuf just fine) even if the uri in the href does not point to a file.

  • the gtk3 dependency should only be necessary for rsvg-view-3 tool, not for rsvg, but it seems to be (or one of the dependencies that got pulled in when I installed gtk3)

  • It still works even after uninstalling gtk3. It even still works after uninstalling gtk3, then rebuilding rsvg (./configure detects: "gtk3: no"), so I figure it must have to do with one of the dependencies that got pulled when I installed gtk3:

  • atk-2.10.0-1-i686

  • hicolor-icon-theme-0.12-2-any
  • gtk-update-icon-cache-2.24.22-1-i686
  • libtasn1-3.3-2-i686
  • p11-kit-0.20.1-1-i686
  • gnutls-3.2.5-1-i686
  • libcups-1.7.0-1-i686
  • libxinerama-1.1.3-2-i686
  • shared-mime-info-1.2-1-i686
  • libgusb-0.1.6-1-i686
  • nspr-4.10.1-2-i686
  • js-17.0.0-1-i686
  • polkit-0.112-1-i686
  • shared-color-profiles-0.1.5-1-any
  • dconf-0.18.0-1-i686
  • colord-1.0.2-2-i686
  • recordproto-1.14.2-1-any
  • libxtst-1.2.2-1-i686
  • at-spi2-core-2.10.1-1-i686
  • at-spi2-atk-2.10.0-1-i686
  • xkeyboard-config-2.10.1-1-any
  • libxkbcommon-0.3.1-1-i686

(I'm leaving these here in case it's not the lib I identified in the end)

So I tried removing these deps in groups and rebuilding and testing in between. Turns out the one making it work is...

* shared-mime-info

molecular
  • 558
  • 5
  • 9
  • In addition it seems to only work when the image file is in the same directory as the svg file, even when using full absolute "file:///..." uri for href. – molecular Oct 30 '13 at 12:11
  • 1
    It helped a log to "#define G_ENABLE_DEBUG" in config.h. rsvg-convert then spits out an actual error about not finding the file. – molecular Oct 30 '13 at 12:12