This script is for converting SVG files to PNG (with transparency support) in MediaWiki. This is done by using Mathieu Leplatre's static compile of librsvg & libcairo, named svgconvert. After rendering, the resulting PNG will be resized to the requested width & height of the thumbnail.
- ImageMagick or GraphicsMagick
- Mathieu Leplatre's svgconvert
ImageMagick / GraphicsMagick is used for resizing the resulting PNG. svgconvert is just the renderer SVG --> PNG. The svgconvert application can actually render to PDF also, but this is not used here. You can download the source code or the binary of the renderer at Mathieu Leplatre's website.
Build svgconvert (or use the binary) and copy the executable and the convert.sh script to a location you prefer. Open convert.sh in your favorite editor and configure the following four settings to your needs:
QUALITY THUMB_ENGINE CONVERT SVGCONVERT
Quality setting for the resulting thumbnail.
This setting defines which application is used for creating the thumbnail:
0: ImageMagick is used. (default)
1: GraphicsMagick is used.
Path to the binary, which creates the thumbnail. If you leave this empty, the default location for the ImageMagick / GraphicsMagick binary will be used. (default: empty)
Path to Mathieu Leplatre's
(default: same folder as the
MediaWiki has to be configured in
LocalSettings.php to use this script
for converting SVGs:
$wgSVGConverterPath = "/path/to/convert.sh"; $wgSVGConverters['svgconverter'] = '$path/convert.sh $input $output $width $height'; $wgSVGConverter = "svgconverter";
You can copy and paste this block to your
LocalSettings.php, but don't forget
to set the correct path in
This will add a new SVG renderer named 'svgconverter', which points to
the convert.sh script. Refer to the MediaWiki documentation
for more details about the different setting variables.
The script does pass an exit status to the parent process:
1: Missing arguments. Check call to script in
2: Source file does not exist.
3: Given thumbnail width is smaller than zero.
4: Given thumbnail height is smaller than zero.
5: Converting the SVG to PNG failed.
6: Thumbnailing the converted PNG failed.
7: Binary of the SVG converter not found. Check
8: Binary the thumbnail engine not found. Check
The default exit status is zero, which indicates that everything should have worked.
MIT-License (see LICENSE file)