1. Go to this page and download the library: Download yoya/php-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/ */
yoya / php-svg example snippets
use SVG\SVGImage;
use SVG\Nodes\Shapes\SVGRect;
// image with 100x100 viewport
$image = new SVGImage(100, 100);
$doc = $image->getDocument();
// blue 40x40 square at (0, 0)
$square = new SVGRect(0, 0, 40, 40);
$square->setStyle('fill', '#0000FF');
$doc->addChild($square);
header('Content-Type: image/svg+xml');
echo $image;
use SVG\SVGImage;
use SVG\Nodes\Shapes\SVGCircle;
$image = new SVGImage(100, 100);
$doc = $image->getDocument();
// circle with radius 20 and green border, center at (50, 50)
$doc->addChild(
(new SVGCircle(50, 50, 20))
->setStyle('fill', 'none')
->setStyle('stroke', '#0F0')
->setStyle('stroke-width', '2px')
);
// rasterize to a 200x200 image, i.e. the original SVG size scaled by 2
$rasterImage = $image->toRasterImage(200, 200);
header('Content-Type: image/png');
imagepng($rasterImage);