sushilk / svg
A modern, secure and fluent PHP library for generating SVG documents.
Fund package maintenance!
v1.0.0
2026-08-29 11:54 UTC
Requires
- php: ^8.4
- ext-xml: *
Requires (Dev)
- laravel/pint: ^1.30
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-11 14:23:34 UTC
README
A modern, secure and fluent PHP 8.4+ library for generating SVG documents.
Installation
composer require sushilk/svg
Quick start
<?php require __DIR__ . '/vendor/autoload.php'; use Svg\Svg; $svg = new Svg(800, 500); $svg->viewBox(0, 0, 800, 500) ->title('Lilac SVG') ->description('Generated with lilac/svg'); $gradient = $svg->defs() ->linearGradient('background') ->from(0, 0) ->to(1, 1); $gradient ->stop(0, '#2563eb') ->stop(1, '#7c3aed'); $svg->rect(0, 0, 800, 500) ->fillUrl('background') ->radius(30); $svg->circle(400, 220, 100) ->fill('#fff'); $svg->text('Lilac SVG', 400, 380) ->fontSize(52) ->fontWeight(700) ->textAnchor('middle') ->fill('#fff'); echo $svg->render(true);
Features
- Fluent SVG API
- Rectangles, circles, ellipses, lines, paths, polygons and polylines
- Text and tspans
- Groups and transforms
- Gradients, patterns, markers, masks and clipping paths
- SVG filters
- SVG animation elements
- XML escaping by default
- Accessibility metadata
- PHP 8.4+
- PSR-4 autoloading
- PHPUnit and PHPStan support
License
MIT. See LICENSE.