PHP code example of atelier / svg

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

    

atelier / svg example snippets


echo Svg::create(120, 120)->circle(60, 60, 50)->fill('#5a8dee')->toString();

use Atelier\Svg\Svg;

$svg = Svg::load('logo.svg')
    ->sanitize()
    ->optimizeWeb();

$svg->save('logo.min.svg');

$svg = Svg::create(200, 100)
    ->rect(10, 10, 80, 80)
    ->circle(150, 50, 40)
    ->fill('#5a8dee');

$svg->toDataUri();   // data:image/svg+xml;... ready for a CSS background

$document = Svg::load('chart.svg')->getDocument();

foreach ($document->querySelectorAll('g[id^="series-"] path') as $path) {
    $path->setAttribute('stroke-width', '2');
}

use Atelier\Svg\Path\Path;

$path = Path::parse('M20,80 C 80,20 220,20 280,80');

$path->getLength();
$path->getPointAtLength(120);   // a Point, for placing a marker along the curve
$path->getBoundingBox();

$safe = Svg::fromString($upload)->sanitize()->toString();

Svg::load('icon.svg')->optimizeWeb()->save('icon.min.svg');

use Atelier\Svg\Element\Accessibility\Accessibility;

Accessibility::setTitle($document, 'Quarterly revenue');
Accessibility::setDescription($document, 'Bar chart comparing Q1 to Q4');

use Atelier\Svg\Morphing\Morph;
use Atelier\Svg\Path\PathParser;

$parser = new PathParser();
$frames = Morph::frames(
    $parser->parse('M 0 0 L 100 0 L 100 100 L 0 100 Z'),
    $parser->parse('M 50 0 L 100 50 L 50 100 L 0 50 Z'),
    60,
    'ease-in-out',
);