PHPackages                             kaareln/php-svg-path-data - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. kaareln/php-svg-path-data

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kaareln/php-svg-path-data
=========================

Add SVG Path Data with object oriented structure

1.0.4(3y ago)03.0k↑13.2%MITPHPPHP &gt;=8.1.0

Since Mar 27Pushed 3y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (3)Used By (0)

php-svg-path-data
=================

[](#php-svg-path-data)

PHP-SVG-PATH-DATA is a PHP library which can help during work with PHP-SVG library. It allows to add SVG path data with object oriented structure.

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

[](#installation)

PHP-SVG-PATH-DATA requires PHP version 8.1 or newer. This package is available on [Packagist](https://packagist.org/packages/kaareln/php-svg-path-data) and can be installed with Composer:

```
$ composer require kaareln/php-svg-path-data
```

Usage
-----

[](#usage)

SVGPath instructions are represented as a string, which can make it difficult to manipulate. However, by using an object representation, the path can be constructed and parsed more easily. This approach also provides the benefits of object-oriented programming, such as the ability to keep references to different parts of the path and manipulate them as needed. This can lead to more efficient and organized code when working with SVGPaths:

```
$path = new SVGPath();

$data = new SVGPathData();

$data->addCommand(new Move(0, 0));

$topLine = new Line(20, 0);
$data->addCommand($topLine);

$rightLine = new Line(20, 20);
$data->addCommand($rightLine);

// at this point I have a references to $topLine and $rightLine, which I can use to modify individually, for example I can move them by 20px

$topLine->x += 20;
$rightLine->x += 20;

// convert the instructions to string and save as d param
$path->setArgument('d', $data->__toString());
```

Using a parser, individual objects representing different parts of a path can be created and modified for more precise changes and greater flexibility:

```
// assume $path is an instanceof SVGPath

$pathData = SVGPathData::fromString($path->getArgument('d'));

// loop for each command in reverse order and possibly change/read parts of the path
foreach ($pathData as $command) {
  if ($command instanceof Line) {
    // move each line coordinates by 20px
    $command->x += 20;
  }
}

// alternatively you can use `transform` method that runs against each command and allows replacing them. In this example I replace all bezier curves with straight lines
$pathData->transform(function (PathDataCommandInterface $command) {
  if ($command instanceof BezierCurve) {
    return new Line($command->x, $command->y);
  }
});

// update the path
$path->setArgument('d', $pathData->__toString());
```

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

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License
-------

[](#license)

[MIT](https://choosealicense.com/licenses/mit/)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1139d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/77a54ba1e95b2f3fc8724ab7cf5dbfd7d163e7deb9b963f6e2e38a301b70aaf0?d=identicon)[kaareln](/maintainers/kaareln)

---

Top Contributors

[![kaareln](https://avatars.githubusercontent.com/u/64361697?v=4)](https://github.com/kaareln "kaareln (31 commits)")

---

Tags

svgSVG PathPHP SVG

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kaareln-php-svg-path-data/health.svg)

```
[![Health](https://phpackages.com/badges/kaareln-php-svg-path-data/health.svg)](https://phpackages.com/packages/kaareln-php-svg-path-data)
```

###  Alternatives

[components/flag-icon-css

A curated collection of all country flags in SVG — plus the CSS for easier integration.

12.0k1.6M23](/packages/components-flag-icon-css)[twbs/bootstrap-icons

Official open source SVG icon library for Bootstrap

7.9k2.0M56](/packages/twbs-bootstrap-icons)[simple-icons/simple-icons

SVG icons for popular brands

24.8k194.2k4](/packages/simple-icons-simple-icons)[rinvex/countries

Rinvex Countries is a simple and lightweight package for retrieving country details with flexibility. A whole bunch of data including name, demonym, capital, iso codes, dialling codes, geo data, currencies, flags, emoji, and other attributes for all 250 countries worldwide at your fingertips.

1.7k7.4M48](/packages/rinvex-countries)[kartik-v/bootstrap-star-rating

A simple yet powerful JQuery star rating plugin for Bootstrap.

1.1k4.5M5](/packages/kartik-v-bootstrap-star-rating)[lipis/flag-icons

A curated collection of all country flags in SVG — plus the CSS for easier integration.

12.0k27.5k4](/packages/lipis-flag-icons)

PHPackages © 2026

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