AtelierSVG
Read, build, and serialise SVG with nothing but PHP.
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.
Documentation
Start
- Installation: install the package and check the PHP requirements.
- Quick start: create, load, edit, and save a first document.
Documents and graphics
- Document API: create, parse, validate, sanitize, and export complete SVG documents.
- Elements: work with shapes, text, gradients, filters, clipping, animation, and accessibility.
- Paths: build path data, inspect geometry, transform segments, and simplify curves.
- Styling: compose transforms, layout values, and presentation attributes.
Production
- Sanitization: remove unsafe content from uploaded SVG.
- Optimization: clean and reduce documents with presets or custom passes.
- Morphing: interpolate compatible outlines and export the animation.