AtelierSVG
Read, build, and serialise SVG with nothing but PHP.
composer require atelier/svg
v1.0.0
Treat SVG as a document, not a string. Generate graphics, edit existing assets, accept uploads safely, and prepare files for production.
Features
- A document, not a string
Every element is a class with its own attributes. Load a file, walk the tree, change it, write it back. - CSS selectors
querySelector()andquerySelectorAll()find the nodes. What comes back is a typed, chainable collection rather than an array. - Paths become segments
Thedattribute parses into typed segments. Measure a length, sample a point along the curve, take a bounding box, simplify, bake a transform into coordinates. - Accept uploads safely
The strict profile removes script elements, event handlers,javascript:URLs and<foreignObject>; two softer ones keep more. Validation is separate, for when you need the report instead of the removal. - Ship smaller files
Forty-seven passes, and four presets that choose for you.optimizeWith()takes a pipeline you assembled instead, and a new pass is an interface rather than a fork. - Morph between shapes
Interpolate two paths whatever their segment counts, then export the frames as SMIL, CSS keyframes, JavaScript, or a sprite sheet.
Create an SVG
use Atelier\Svg\Svg;
Svg::create(300, 200)
->rect(0, 0, 300, 200, ['fill' => '#0f172a'])
->circle(150, 100, 60, ['fill' => '#6366f1'])
->save('output.svg');
Make an uploaded SVG safe
use Atelier\Svg\Svg;
use Atelier\Svg\Sanitizer\SanitizeProfile;
Svg::load('untrusted.svg')
->sanitize(SanitizeProfile::STRICT)
->save('safe.svg');
Prepare an icon for the web
Svg::load('icon.svg')
->optimizeWeb()
->save('icon.min.svg');
optimizeWeb() removes delivery-only weight such as dimensions and unused IDs. Use optimizeSafe() for design assets where metadata and IDs must remain intact.
Install
composer require atelier/svg