Skip to content

PHP extension based on RSVG library to quickly convert SVG files into EPS, PDF, PNG and SVG again.

Notifications You must be signed in to change notification settings

vaibhavpandeyvpz/php-rsvg

Repository files navigation

php-rsvg

PHP extension based on RSVG library to quickly convert SVG files into EPS, PDF, PNG and SVG again.

Requirements

Installation

To build and install the module, clone the project and run below command:

phpize
./configure
make
make install

Then enable the extension in your php.ini

extension=rsvg.so

To try out the extension, you can run the following command

php -a -d extension=modules/rsvg.so

Usage

Once 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., ''.

About

PHP extension based on RSVG library to quickly convert SVG files into EPS, PDF, PNG and SVG again.

Topics

Resources

Stars

Watchers

Forks