Installing librsvg

This document describes how to compile and install librsvg, a free SVG rendering library written as part of the GNOME project.

It can be used to convert SVG vector images to PNG raster images using the rsvg-convert program. Some web software (such as MediaWiki) uses rsvg-convert in order to render PNG versions or thumbnails of SVG images.

Obtain the source code
You will need recent versions of the following packages. (The version numbers listed here are ones that are known to work, though you should probably try to get the latest version of each package.)


 * 1) libffi 3.0.13
 * 2) glib 2.36.0
 * 3) libcroco 0.6.8
 * 4) gobject-introspection 1.36.0
 * 5) gdk-pixbuf 2.28.0
 * 6) pixman 0.28.2
 * 7) cairo 1.12.14
 * 8) harfbuzz 0.9.14
 * 9) freetype 2.4.11
 * 10) fontconfig 2.10.91
 * 11) pango 1.34.0
 * 12) librsvg 2.37.0

You can use wget to download the files to $HOME/src and extract them there: $ mkdir ~/src $ cd ~/src $ wget URL $ tar xavf FILENAME

Environment variables
Set up your environment variables by issuing the following commands:

$ export PKG_CONFIG_PATH=$HOME/lib/pkgconfig $ export PATH=$HOME/bin:$PATH $ export LDFLAGS=-L$HOME/lib $ export LD_LIBRARY_PATH=$HOME/lib $ export CPPFLAGS=-I$HOME/include

Compilation and installation
Install packages in the order shown above. (If you use a different order, the packages may not configure or compile correctly.)

For all packages except gdk-pixbuf, you install the packages as follows, substituting PACKAGEDIR with the directory containing the package:

$ cd ~/src/PACKAGEDIR $ ./configure --prefix=$HOME $ make $ make install

For gdk-pixbuf, substitute the following configure command:

$ ./configure --prefix=$HOME --without-libtiff

Result
The rsvg-convert executable will be placed in $HOME/bin:

$ ~/bin/rsvg-convert --help Usage: rsvg-convert [OPTION...] [FILE...] - SVG Converter Help Options: -?, --help                                                 Show help options Application Options: -d, --dpi-x=                                        pixels per inch [optional; defaults to 90dpi] -p, --dpi-y=                                        pixels per inch [optional; defaults to 90dpi] -x, --x-zoom=                                       x zoom factor [optional; defaults to 1.0] -y, --y-zoom=                                       y zoom factor [optional; defaults to 1.0] -z, --zoom=                                         zoom factor [optional; defaults to 1.0] -w, --width=                                          width [optional; defaults to the SVG's width] -h, --height=                                         height [optional; defaults to the SVG's height] -f, --format=[png, pdf, ps, svg]                           save format [optional; defaults to 'png'] -o, --output                                               output filename [optional; defaults to stdout] -a, --keep-aspect-ratio                                    whether to preserve the aspect ratio [optional; defaults to FALSE] -b, --background-color=[black, white, #abccee, #aaa...]    set the background color [optional; defaults to None] -v, --version                                              show version information --base-uri                                                 base uri

Adding librsvg support to MediaWiki
To enable your MediaWiki installation to use librsvg to generate PNG thumbnails of SVG images, add the following to your GlobalSettings.php</tt> or LocalSettings.php</tt> file, replacing /PATH/TO</tt> with the value of $HOME/bin</tt>:

$wgSVGConverters['rsvg'] = '/PATH/TO/rsvg-convert -w $width -h $height -o $output $input'; $wgSVGConverter = 'rsvg';

Note that older versions of MediaWiki don't work well with newer versions of librsvg. In particular, version 1.16 does not seem to work with librsvg 2.37.0, whereas version 1.19.2 does. You may need to upgrade your MediaWiki installation if you want to use the latest librsvg.

Troubleshooting MediaWiki If you encounter errors like "symbol not found in xxxx.so.0" you're likely running into library hell. When rsvg-convert runs it's linking to the incorrect libraries. You can diagnose this by running 'ldd rsvg-convert' to see the libraries it's linking to. Unfortunately even when it worked for me in the shell I had to force it to use $HOME/lib by wrapping it in a script. I created $/home/bin/rsvg-convert-wrapped with these contents:

#!/bin/bash export LD_LIBRARY_PATH="$HOME/lib:$LD_LIBRARY_PATH" $HOME/rsvg-convert "$@"

Then you have to set a+x on the script and change the LocalSettings.php.