2

I've got an SVG image as follows that I'm trying to convert to a PNG:

<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink">
  <image x="0" y="0" width="158" height="158"
     xlink:href="http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png" />
</svg>

This was working on Ubuntu 10.04, but now on 12.04 it doesn't. The reason appears to be that RSVG now won't load any image URL that doesn't have a relative path.

That's not an option here - my website generates the SVG (so I know it's safe) but it requires that the images are loaded in via HTTP.

The image displays fine in Chrome, but not in Imagemagick, Gimp, or (strangely) Inkscape.

If it helps I'm using Imagemagick via PHP, but RSVG is the delegate for SVG conversion here.

Does anyone have any ideas for how to get around this, short of recompiling librsvg?

I've tried the suggestions at ImageMagick (RSVG) won't import images in SVG and it looks suspiciously like it's this problem: rsvg doesn't render linked images


I found the code that's responsible here: https://git.gnome.org/browse/librsvg/tree/rsvg-base.c#n2169

I could be wrong, but it seems like they've disabled loads from other URLs, without any way to re-enable it short of a recompile?

Community
  • 1
  • 1
Gordon Williams
  • 1,856
  • 1
  • 17
  • 31
  • 1
    As librsvg is shared across the gnome/gtk family, it's pretty important to have a strict *deny* on remote resources. If your already using PHP, it wouldn't take much effort to pull down remote resources with [file_get_contents](http://php.net/manual/en/function.file-get-contents.php) & modify the SVG with [DOMDocument](http://php.net/manual/en/book.dom.php) – emcconville Oct 14 '14 at 16:32
  • That is actually what I'm doing now. It really sucks that something like librsvg can change so drastically between versions that it'll just stop working without warning and will become effectively useless (as there's not even a way to re-enable the old behaviour). @emcconville do you want to post a solution for this so I can accept it? My solution is pretty evil and not general purpose because I know the URL format that will be in the SVG I created. – Gordon Williams Oct 14 '14 at 16:56
  • 2
    Hmm. Do you really need rsvg? Depending on the complexity of the svg images, you might be able to use IM's internal vector graphics engine. Does the following command work on your system? `convert -size 158x158 msvg:source.svg out.png` – emcconville Oct 14 '14 at 17:56
  • Thanks! MSVG works! My SVGs are not super-complex, they just use rotation, text, images and rounded rects. Any ideas how I can force PHP Imagick to use it? Of course Imagemagick may choose to modify MSVG in the future too - so maybe the original solution is better... – Gordon Williams Oct 15 '14 at 12:03
  • Actually - when I run 'convert msvg:' on the images I make, it doesn't work either for some reason - so back to Option 1. One more option (in my case) is to serve the SVG file from the same webserver that the images are on, and then to load it from HTTP for the conversion - that solves the same-origin issues. – Gordon Williams Oct 15 '14 at 12:19

0 Answers0