mober / phpsvg
Edit and create SVG Documents using OO PHP
v6.0.0-beta.2
2026-03-15 15:45 UTC
Requires
- php: ^8.2
- ext-dom: *
- ext-fileinfo: *
- ext-simplexml: *
- symfony/polyfill-php83: ^1.33
Requires (Dev)
- squizlabs/php_codesniffer: ^4.0
- vimeo/psalm: ^6.0
Suggests
- ext-imagick: Export images using Imagick
- ext-zlib: Read/write compressed files
- dev-master
- v6.0.0-beta.2
- v6.0.0-beta.1
- v5.0.1
- v5.0.0
- v4.0.1
- v4.0.0
- v4.0.0-beta.7
- v4.0.0-beta.6
- v4.0.0-beta.5
- v4.0.0-beta.4
- v4.0.0-beta.3
- v4.0.0-beta.2
- v4.0.0-beta.1
- v3.1.3
- v3.1.2
- v3.1.1
- v3.0.0
- v3.0.0-beta.5
- v3.0.0-beta.4
- v3.0.0-beta.3
- v3.0.0-beta.2
- v3.0.0-beta.1
- v2.0.1
- v2.0.0
- v1.0.1
- v1.0.0
- dev-php-update
This package is auto-updated.
Last update: 2026-03-15 15:46:15 UTC
README
Edit and create SVG documents using PHP.
This library is a fork of mewebstudio/phpsvg, which was last updated in 2013.
Features
- Open and edit SVG and SVGZ (GZipped)
- Generate thumbnails or export to PNG, JPG, GIF, PS, EPS, PDF
- Support embedded or linked images
- Strict typing, i.e.
declare(strict_types=1);
Installation
- Version 4.x supports PHP 8.0 and newer, because some features (like fluent methods) require language features that were not available in earlier versions.
- Version 3.x is no longer maintained and supports PHP 7.1 to 8.0.
Install using composer:
composer require mober/phpsvg
Example
$svg = new SVGDocument(); $gradient = new SVGLinearGradient([ // Set style using fluent methods (new SVGStop(0))->setColor('blue')->setOpacity(1), (new SVGStop(0.8))->setColor('cyan')->setOpacity(0.5), ]); $svg->addDefs($gradient); $svg->addShape( new SVGRect(10, 20, '100', '200', (new SVGStyle())->setFill($gradient)) ); $radial = new SVGRadialGradient([ // Set style as string new SVGStop(0, 'stop-color:yellow;stop-opacity:1'), new SVGStop(0.7, 'stop-color:green;stop-opacity:1'), ]); $svg->addDefs($radial); $svg->addShape( new SVGCircle(250, 120, 100, (new SVGStyle())->setFill($radial)) ); $svg->writeXML('demo.svg', humanReadable: true);