PHPackages                             atelier/svg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. atelier/svg

ActiveLibrary

atelier/svg
===========

PHP library for SVG manipulation, optimization, and morphing: parsing, building, styling, transforms, validation, and sanitization

10PHPCI passing

Since Apr 6Pushed 2d agoCompare

[ Source](https://github.com/ateliersvg/svg)[ Packagist](https://packagist.org/packages/atelier/svg)[ RSS](/packages/atelier-svg/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Atelier SVG
===========

[](#atelier-svg)

[![CI](https://github.com/smnandre/atelier-svg/actions/workflows/ci.yml/badge.svg)](https://github.com/smnandre/atelier-svg/actions/workflows/ci.yml)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP 8.3+](https://camo.githubusercontent.com/278621fc49c71cdc38414030199af0284d7323979cad78496bfafbf7050ee4bc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d3737374242342e737667)](https://php.net)

Designed precisely. Built to scale.

A PHP library for SVG manipulation, optimization, and morphing. Parse, build, style, transform, validate, sanitize, and animate SVG graphics with a type-safe, fluent API.

**[Quick Start](#quick-start) | [Features](#features) | [Use Cases](#use-cases) | [Documentation](#documentation)**

---

Installation
------------

[](#installation)

```
composer require atelier/svg
```

Requires PHP 8.3+.

---

Quick Start
-----------

[](#quick-start)

```
use Atelier\Svg\Svg;

Svg::create(300, 200)
    ->rect(0, 0, 300, 200, ['fill' => '#1e293b'])
    ->circle(150, 100, 60, ['fill' => '#3b82f6'])
    ->text(150, 180, 'Atelier SVG', ['text-anchor' => 'middle', 'fill' => '#fff'])
    ->optimize()
    ->save('output.svg');
```

Load, query, modify, save:

```
$svg = Svg::load('input.svg');

$svg->getDocument()
    ->querySelectorAll('circle')
    ->fill('#3b82f6')
    ->stroke('#000')
    ->strokeWidth(2);

$svg->optimize()->save('output.svg');
```

---

Features
--------

[](#features)

### Elements

[](#elements)

Full SVG 1.1 element support: shapes, text, groups, symbols, markers, gradients, filters, clipping, masking, and animation: all as typed PHP classes.

```
$text = TextElement::create(10, 30, 'Hello');

$builder = new TspanBuilder($text);
$builder->add('Bold', 0, ['font-weight' => 'bold'])
    ->add('and italic', 10, ['font-style' => 'italic']);
```

```
$symbol = SymbolBuilder::createSymbol($document, 'icon-star', '0 0 24 24');
SymbolBuilder::useSymbol($document, 'icon-star', 10, 10);

$marker = MarkerBuilder::arrow($document, 'arrow-end', '#000', 10);
```

```
AnimationBuilder::fadeIn($element, '1s');
AnimationBuilder::rotate($element, 0, 360, '2s');
```

[Elements documentation](./docs/elements/overview.md): Shapes, text, structural elements, selectors, accessibility

### Filters &amp; Effects

[](#filters--effects)

26+ filter primitives, linear and radial gradients, patterns, clipping, and masking: with fluent builders.

```
FilterBuilder::createDropShadow($document, 'shadow', 2, 2, 4, '#000', 0.3);

FilterBuilder::create($document, 'glow')
    ->gaussianBlur(3, 'SourceAlpha', 'blur')
    ->flood('#3b82f6', 0.8, 'color')
    ->composite('in', 'color', 'blur', 'glow')
    ->blend('normal', 'SourceGraphic', 'glow')
    ->addToDefs();
```

```
GradientBuilder::horizontal($document, 'sunset', '#ff6b6b', '#feca57');

GradientBuilder::createLinear($document, 'custom')
    ->from(0, 0)->to(100, 100)
    ->addStop(0, '#3b82f6')
    ->addStop(50, '#8b5cf6', 0.8)
    ->addStop(100, '#ec4899')
    ->addToDefs();
```

[Filters documentation](./docs/elements/filters/overview.md): [Gradients](./docs/elements/gradients/linear.md): [Clipping &amp; Masking](./docs/elements/clipping.md)

### Paths

[](#paths)

Type-safe path building, geometric analysis, distance metrics, and simplification.

```
$data = PathBuilder::startAt(10, 10)
    ->lineTo(50, 50)
    ->curveTo(250, 50, 300, 50, 350, 100)
    ->arcTo(50, 50, 0, false, true, 500, 100)
    ->closePath()
    ->toData();

$analyzer = new PathAnalyzer($data);
$length = $analyzer->getLength();
$bbox = $analyzer->getBoundingBox();
$inside = $analyzer->containsPoint(new Point(25, 25));
```

[Path documentation](./docs/path/overview.md): Building, analysis, transforms, simplification

### Optimization

[](#optimization)

A configurable pipeline with 40+ passes, inspired by SVGO. Four presets, or build your own.

```
Svg::load('input.svg')->optimize()->save('output.svg');
```

**Before:**

```

```

**After:**

```

```

```
$optimizer = new Optimizer(OptimizerPresets::default());      // Balanced
$optimizer = new Optimizer(OptimizerPresets::aggressive());   // Maximum reduction
$optimizer = new Optimizer(OptimizerPresets::safe());         // Conservative
$optimizer = new Optimizer(OptimizerPresets::accessible());   // Keeps a11y metadata
```

[Optimization documentation](./docs/optimization/overview.md): Passes, presets, custom pipelines

### Security &amp; Validation

[](#security--validation)

Sanitize untrusted SVGs, validate against the spec, check accessibility.

```
Sanitizer::strict()->sanitize($document);   // Remove scripts, event handlers, JS URLs
Sanitizer::default()->sanitize($document);  // Balanced security
```

```
$validator = new Validator(ValidationProfile::strict());
$result = $validator->validate($document);

$broken = DocumentValidator::findBrokenReferences($document);
DocumentValidator::autoFix($document);
```

```
$issues = Accessibility::checkAccessibility($document);
Accessibility::setTitle($document, 'Sales Chart Q1 2025');
Accessibility::improveAccessibility($document);
```

[Validation documentation](./docs/document/validation.md): [Sanitization](./docs/document/sanitization.md): [Accessibility](./docs/elements/accessibility.md)

### Morphing

[](#morphing)

Interpolate between SVG shapes with easing. Export to SMIL, CSS keyframes, or JavaScript.

```
$midPath = Morph::between($startPath, $endPath, 0.5);

$frames = Morph::create()
    ->from($startPath)
    ->to($endPath)
    ->withDuration(2000, 60)
    ->withEasing('ease-in-out')
    ->generate();

$doc = AnimationExporter::toAnimatedSVG($frames, ['duration' => 3]);
$css = AnimationExporter::toCSSKeyframes($frames, 'my-morph');
```

[Morphing documentation](./docs/morphing/overview.md): Interpolation, easing, exporting

---

Use Cases
---------

[](#use-cases)

### Sanitize user-uploaded SVGs

[](#sanitize-user-uploaded-svgs)

Accept SVGs from users without risking XSS. Strip scripts and dangerous content, validate structure, optimize, and serve.

```
$svg = Svg::load($uploadedFile);
$document = $svg->getDocument();

Sanitizer::strict()->sanitize($document);
DocumentValidator::autoFix($document);

$svg->optimize()->save($outputPath);
```

### Generate icon sprite sheets

[](#generate-icon-sprite-sheets)

Consolidate individual icon files into a single SVG sprite for fewer HTTP requests.

```
$icons = array_map(fn ($file) => Svg::load($file)->getDocument(), glob('icons/*.svg'));

$sprite = Document::merge($icons, ['strategy' => MergeStrategy::SYMBOLS]);
```

```

```

### Batch-process SVG assets

[](#batch-process-svg-assets)

Optimize an entire directory of SVGs in a CI pipeline or build step.

```
$optimizer = new Optimizer(OptimizerPresets::aggressive());

foreach (glob('assets/svg/*.svg') as $file) {
    $document = (new DomLoader())->loadFromFile($file);
    $optimizer->optimize($document);
    (new CompactXmlDumper())->dumpToFile($document, $file);
}
```

### Build charts and dashboards

[](#build-charts-and-dashboards)

Compose SVG documents programmatically: generate charts, combine them into layouts, add accessible metadata.

```
$chart = Svg::create(400, 300);

foreach ($data as $i => $value) {
    $height = $value * 2;
    $chart->rect($i * 50 + 10, 300 - $height, 40, $height, ['fill' => '#3b82f6']);
}

Accessibility::setTitle($chart->getDocument(), 'Monthly Revenue');
Accessibility::setDescription($chart->getDocument(), 'Bar chart showing revenue by month');

$chart->save('chart.svg');
```

### Animate shape transitions

[](#animate-shape-transitions)

Morph between two SVG shapes and export as a self-contained animated SVG.

```
$star = Svg::load('star.svg')->getDocument()->querySelector('path');
$circle = Svg::load('circle.svg')->getDocument()->querySelector('path');

$frames = Morph::frames(
    Path::parse($star->getAttribute('d'))->getData(),
    Path::parse($circle->getAttribute('d'))->getData(),
    60,
    'ease-in-out',
);

$animated = AnimationExporter::toAnimatedSVG($frames, [
    'duration' => 2,
    'repeatCount' => 'indefinite',
]);
```

---

Documentation
-------------

[](#documentation)

- [Getting Started](./docs/getting-started/installation.md): Installation and quick start
- [Document Handling](./docs/document/overview.md): Creating, loading, exporting, sanitization, validation
- [Elements](./docs/elements/overview.md): Shapes, text, animation, selectors, gradients, filters, clipping
- [Path Operations](./docs/path/overview.md): Building, analysis, transforms, geometry, simplification
- [Styling](./docs/styling/overview.md): Layout, transforms, and values
- [Optimization](./docs/optimization/overview.md): Passes and presets
- [Morphing](./docs/morphing/overview.md): Interpolation, easing, exporting
- [Guides](./docs/guides/sanitize-uploads.md): Sanitization, batch processing, charts, animation

---

Contributing
------------

[](#contributing)

Contributions are welcome! See [CONTRIBUTING.md](.github/CONTRIBUTING.md) for guidelines.

License
-------

[](#license)

Atelier SVG is open-source software licensed under the [MIT License](LICENSE).

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance65

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8951d49b371d210280a58ce48969a07d1f49924810f8a1fab3a9343eb46fdc9?d=identicon)[simonandre](/maintainers/simonandre)

---

Top Contributors

[![smnandre](https://avatars.githubusercontent.com/u/1359581?v=4)](https://github.com/smnandre "smnandre (1 commits)")

---

Tags

php-svgphp-svgosvg

### Embed Badge

![Health badge](/badges/atelier-svg/health.svg)

```
[![Health](https://phpackages.com/badges/atelier-svg/health.svg)](https://phpackages.com/packages/atelier-svg)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
