Installing librsvg
| The instructions provided in this article or section are considered advanced. You are expected to be knowledgeable in the UNIX shell. |
| The instructions provided in this article or section require shell access unless otherwise stated. You can use the PuTTY client on Windows, or SSH on UNIX and UNIX-like systems such as Linux or Mac OS X. |
Contents |
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.)
- libffi 3.0.13
- glib 2.36.0
- libcroco 0.6.8
- gobject-introspection 1.36.0
- gdk-pixbuf 2.28.0
- pixman 0.28.2
- cairo 1.12.14
- harfbuzz 0.9.14
- freetype 2.4.11
- fontconfig 2.10.91
- pango 1.34.0
- 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=<float> pixels per inch [optional; defaults to 90dpi] -p, --dpi-y=<float> pixels per inch [optional; defaults to 90dpi] -x, --x-zoom=<float> x zoom factor [optional; defaults to 1.0] -y, --y-zoom=<float> y zoom factor [optional; defaults to 1.0] -z, --zoom=<float> zoom factor [optional; defaults to 1.0] -w, --width=<int> width [optional; defaults to the SVG's width] -h, --height=<int> 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 or LocalSettings.php file, replacing /PATH/TO with the value of $HOME/bin:
$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.