PHP code example of nplavsic / phpsvg

1. Go to this page and download the library: Download nplavsic/phpsvg 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/ */

    

nplavsic / phpsvg example snippets






$svg = SVGDocument::getInstance( 'resource/apple.svg' ); //open to edit

//$svg = SVGDocument::getInstance( ); //default read to use



$rect = #create a new rect with, x and y position, id, width and heigth, and the style

$rect = SVGRect::getInstance( 0, 5, 'myRect', 228, 185, new SVGStyle( array( 'fill'   => 'red', 'stroke' => 'blue' ) ) );

$svg->addShape( $rect );



$text = SVGText::getInstance( 22, 50, 'myText', 'This is a text', $style );



$svg->asXML('output/output.svg'); //output to svg file

$svg->export('output/output.png'); //export as png

$svg->export('output/thumb32x32.png',32,32); //export thumbnail

$svg->output(); //echo with header to browser