PHPackages                             jangobrick/php-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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. jangobrick/php-svg

Abandoned → [meyfa/php-svg](/?search=meyfa%2Fphp-svg)Library[Parsing &amp; Serialization](/categories/parsing)

jangobrick/php-svg
==================

Read, edit, write, and render SVG files with PHP

v0.16.1(1y ago)53531.2k100[14 issues](https://github.com/meyfa/php-svg/issues)[6 PRs](https://github.com/meyfa/php-svg/pulls)1MITPHPPHP &gt;=7.4.0CI passing

Since Sep 19Pushed 7mo ago13 watchersCompare

[ Source](https://github.com/meyfa/php-svg)[ Packagist](https://packagist.org/packages/jangobrick/php-svg)[ Docs](https://github.com/meyfa/php-svg)[ RSS](/packages/jangobrick-php-svg/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (38)Used By (1)

PHP-SVG
=======

[](#php-svg)

**The zero-dependency vector graphics library for PHP applications**

[![CI](https://github.com/meyfa/php-svg/actions/workflows/php.yml/badge.svg)](https://github.com/meyfa/php-svg/actions/workflows/php.yml)[![Packagist PHP Version](https://camo.githubusercontent.com/f1782b003abf4b567a79a1b4590d08226cdc35a17f7d0c4e414081d48852d648/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6d657966612f7068702d7376672f7068703f7374796c653d706c6173746963)](https://camo.githubusercontent.com/f1782b003abf4b567a79a1b4590d08226cdc35a17f7d0c4e414081d48852d648/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6d657966612f7068702d7376672f7068703f7374796c653d706c6173746963)[![Packagist Downloads](https://camo.githubusercontent.com/7c307f8dab67c16a9cefbad4e7c48f47b37f2e1c8101c22048556d5c4f1ac6d7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d657966612f7068702d737667)](https://packagist.org/packages/meyfa/php-svg)

Features
--------

[](#features)

PHP-SVG can help with the following set of tasks:

- Generating vector graphics programmatically with PHP code. The resulting SVG string can be written to a file or sent as part of the HTTP response.
- Loading and parsing SVG images into document trees that are easy to modify and append.
- Converting vector graphics into raster image formats, such as PNG or JPEG (rasterization).

Please note that PHP-SVG is still in its alpha stage and may not be suitable for complex applications, yet. Contributions are very welcome. [Find out how to contribute](#contributing).

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

[](#installation)

### Requirements

[](#requirements)

PHP-SVG is free of dependencies. All it needs is a PHP installation satisfying the following requirements:

- PHP version 7.4 or newer. This library is tested against all versions up to (and including) PHP 8.4.
- If you wish to load SVG files, or strings containing SVG code, you need to have the ['simplexml' PHP extension](https://www.php.net/manual/en/book.simplexml.php).
- If you wish to use the rasterization feature for converting SVGs to raster images (PNGs, JPEGs, ...), you need to have the ['gd' PHP extension](https://www.php.net/manual/en/book.image.php).

These extensions are almost always available on typical PHP installations. Still, you might want to make sure that your hosting provider actually has them. If SimpleXML or GD are missing, PHP-SVG can still perform all tasks except those that require the missing extension. For example, programmatically generating SVG images and outputting them as XML will always work, even without any extension.

### Composer (recommended)

[](#composer-recommended)

This package is available on [Packagist](https://packagist.org/packages/meyfa/php-svg) and can be installed with Composer:

```
composer require meyfa/php-svg
```

This adds a dependency to your composer.json file. If you haven't already, setup autoloading for Composer dependencies by adding the following `require` statement at the top of your PHP scripts:

```
 tag needed for standalone SVG files:
$xmlString = $image->toXMLString();
file_put_contents('my-image.svg', $xmlString);

// This will omit the  tag for outputting directly into HTML:
$xmlString = $image->toXMLString(false);
echo '' . $xmlString . '';
```

### Loading SVGs from strings

[](#loading-svgs-from-strings)

In addition to generating images programmatically from scratch, they can be parsed from strings or loaded from files. The following code parses an SVG string, mutates part of the image, and echoes the result to the client:

```
