PHP code example of msztorc / svg-convert

1. Go to this page and download the library: Download msztorc/svg-convert library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

msztorc / svg-convert example snippets


$svg = (new SVG)->init('phantomjs');

$svg = (new SVG)->init('rsvg');



    $svg = (new SVG)->init('phantomjs', 'inputfile.svg');
    $svg->setFormat('png');
    $svg->convert();
    $svg->save('outputfile.png');



    $svg = (new SVG)->init('phantomjs', 'inputfile.svg');
    $svg->setAttribute('path', 'fill', '#131C77'); //change fill color to all paths
    $svg->setFormat('png');
    $svg->convert();
    $svg->save('outputfile.png');

$svg->open('file.svg'); //open file

$svg->setZoom(2.5); //enlarge original svg size up to 2.5x

$svg->setWidth(500); //set output width to 500px
$svg->setHeight(300); //set output height to 300px

//echo 'output size: ' . $svg->getWidth() . 'x' . $svg->getHeight();

$svg->setFormat('pdf'); //set output format to pdf

//echo 'output format: ' . $svg->getFormat();

$svg->display(); //display image

$svg->download(); //download file

$svg->save('file.png'); //save file