PHP extension based on RSVG library to quickly convert SVG files into EPS, PDF, PNG and SVG again.
To build and install the module, clone the project and run below command:
phpize
./configure
make
make installThen enable the extension in your php.ini
extension=rsvg.soTo try out the extension, you can run the following command
php -a -d extension=modules/rsvg.soOnce loaded, you can use below functions to process SVG files:
<?php
// read SVG file contents
$svg_contents = file_get_contents('qrcode.svg');
// convert from SVG to PNG
$png_contents = rsvg_convert($svg_contents, 'png', '#ffffff'); // can also pass 'eps', 'pdf' or 'svg'
// can also convert b/w files directly
rsvg_convert_file('qrcode.svg', 'qrcode.png', 'png', '#ffffff');In above examples, #ffffff is the background color to be used for output.
To output an image with transparent background, supply an empty string i.e., ''.