PHPackages                             gymmed/svg-parser - 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. gymmed/svg-parser

ActiveLibrary

gymmed/svg-parser
=================

Includes css document styles to svg without editing original svg document.

v0.1(1y ago)010MITPHP

Since Sep 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/GymMed/Svg-Parser-PHP)[ Packagist](https://packagist.org/packages/gymmed/svg-parser)[ Docs](https://github.com/GymMed/Svg-Parser-PHP)[ RSS](/packages/gymmed-svg-parser/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

 Svg Parser PHP
================

[](#----svg-parser-php)

 [![Applying styles to svg.](./preview/images/svg-parser-gymmed.png)](./preview/images/svg-parser-gymmed.png)

Applies CSS document styles to an SVG without modifying the original SVG file. It also parses CSS variables and inserts their values directly into CSS selectors styles, as it is intendent for broader use than just for browser rendering.

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

[](#installation)

You can install the package via composer:

```
composer require gymmed/svg-parser-php
```

Use Case
--------

[](#use-case)

[Dompdf](https://github.com/dompdf/dompdf) or laravel wrapper [laravel-dompdf](https://github.com/barryvdh/laravel-dompdf)don't support direct SVG import or requires the inclusion of external SVG files. This library provides a way to attach CSS documents to SVG files without needing to directly modify the SVG.

If you stumble upon the same problem, I highly recommend using [imagick](https://github.com/Imagick/imagick)or [rasterize-svg](https://github.com/choowx/rasterize-svg) to convert the SVG to PNG and include it in the PDF. This way, you reduce the chances of the styles being rendered incorrectly by [Dompdf](https://github.com/dompdf/dompdf)and won't need two different CSS documents or two SVG files.

Usage
-----

[](#usage)

```
use GymMed\SvgParser;

//provide full path
$svgPath = realpath(__DIR__ . "./assets/example.svg");
$cssPath = realpath(__DIR__ . "./assets/css/index.css");

$svgWithCSS = SvgParser::formatSvgFromPath($svgPath, [$cssPath]);
```

or use SVG content:

```
use GymMed\SvgParser;

//provide full path
$svgPath = realpath(__DIR__ . "./assets/example.svg");
$cssPath = realpath(__DIR__ . "./assets/css/index.css");
$svg = file_get_contents($svgPath);

$svgWithCSS = SvgParser::formatSvg($svg, [$cssPath]);
```

If you want to write simple CSS and apply it inside SVG:

```
use GymMed\SvgParser;

//provide full path
$svgPath = realpath(__DIR__ . "./assets/example.svg");
$svg = file_get_contents($svgPath);

$svgWithCSS = SvgParser::getParsedCSSToSvg($svg, ".circle { background-color: red; border-radius: 50% }");
```

If you want to provide only full path instead of SVG itself:

```
use GymMed\SvgParser;

//provide full path
$svgPath = realpath(__DIR__ . "./assets/example.svg");

$svgWithCSS = SvgParser::getParsedCSSToSvgFromPath($svgPath, ".circle { background-color: red; border-radius: 50% }");
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity30

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

600d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1369ecac7ae435fa977eb85d85ee4a8a79789b6964490e22a84782898cf19823?d=identicon)[GymMed](/maintainers/GymMed)

---

Top Contributors

[![GymMed](https://avatars.githubusercontent.com/u/91053179?v=4)](https://github.com/GymMed "GymMed (6 commits)")

---

Tags

csssmallphpsvggymmedsvg-parser-phpsvg-parsercss-svg

### Embed Badge

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

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

###  Alternatives

[picqer/php-barcode-generator

An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.

1.8k25.5M85](/packages/picqer-php-barcode-generator)[jkphl/iconizr

A PHP command line tool for converting SVG images to a set of CSS icons (SVG &amp; PNG, single icons and / or CSS sprites) with support for image optimization and Sass output

4868.9k](/packages/jkphl-iconizr)[tomloprod/radiance

A deterministic mesh gradient avatar generator for PHP.

1393.7k](/packages/tomloprod-radiance)[choowx/rasterize-svg

A PHP library for converting SVG to JPEG, PNG, and WEBP

2261.7k](/packages/choowx-rasterize-svg)

PHPackages © 2026

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