I wanted librsvg image rendering to work on my Mac to speed up SVG rendering. Ian McKinnon has a great answer with all the ingredients, but implementing changes in the library is complex. These steps made librsvg correctly display related images with relative paths. Hope this saves you a little time.
First I installed librsvg using:
brew install
At the time of this writing for installation, this installs version 2.40.13 and the required libraries. Then I downloaded and extracted the source archive into my home directory:
wget https://download.gnome.org/sources/librsvg/2.40/librsvg-2.40.13.tar.xz tar jxvf librsvg-2.40.13.tar.xz cd librsvg-2.40.13
I edited the _rsvg_handle_allow_load function in rsvg-base.c in this directory to get around the limitations of loading the path by adding this code to line 2275:
2275 2276 goto allow;
I also needed to edit the rsvg_cairo_surface_new_from_href function in rsvg-image.c and stop its loading using mime types - just replace the function as follows:
55 if (mime_type) { 56
I needed to use these slightly modified commands to compile and install the modified library:
make clean make install gdk_pixbuf_binarydir=/usr/local/Cellar/librsvg/2.40.13/lib/gdk-pixbuf-2.0/2.10.0/loaders gdk_pixbuf_moduledir=/usr/local/Cellar/librsvg/2.40.13/lib/gdk-pixbuf-2.0/2.10.0/loaders
Depending on your system, you may need to add sudo to the commands above.
Once this has been done, I can display the relative SVG links using the rsvg-convert command-line rsvg-convert installed with librsvg:
rsvg-convert test.svg -o test.png
I was also able to use ImageMagick to convert SVG with relative links to images in PNG files if I installed it after installing librsvg as follows:
convert test.svg test.png
This will allow you to test the rsvg function and performance - I found that it was 2-3 times faster than Inkscape for my application. I recommend changing the code more intelligently if you use it in a production environment.
Luke stutters
source share