PHP code example of mober / phpsvg

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

    

mober / phpsvg example snippets


$svg = new SVGDocument();

$gradient = new SVGLinearGradient([
    // Set style using fluent methods
    (new SVGStop(0))->setColor('blue')->setOpacity(1),
    (new SVGStop(0.8))->setColor('cyan')->setOpacity(0.5),
]);
$svg->addDefs($gradient);
$svg->addShape(
    new SVGRect(10, 20, '100', '200', (new SVGStyle())->setFill($gradient))
);

$radial = new SVGRadialGradient([
    // Set style as string
    new SVGStop(0, 'stop-color:yellow;stop-opacity:1'),
    new SVGStop(0.7, 'stop-color:green;stop-opacity:1'),
]);
$svg->addDefs($radial);
$svg->addShape(
    new SVGCircle(250, 120, 100, (new SVGStyle())->setFill($radial))
);

$svg->writeXML('demo.svg', humanReadable: true);