PHPackages                             vierwd/svg-inliner - 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. vierwd/svg-inliner

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

vierwd/svg-inliner
==================

Utility functions to inline SVGs in PHP Projects

1.4.1(3y ago)19.1k↓32.9%1MITPHPPHP ^7.4.0 | ^8.0 | ^8.1

Since Aug 13Pushed 3y ago2 watchersCompare

[ Source](https://github.com/4wdmedia/svg-inliner)[ Packagist](https://packagist.org/packages/vierwd/svg-inliner)[ RSS](/packages/vierwd-svg-inliner/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (6)Versions (8)Used By (1)

svg-inliner
===========

[](#svg-inliner)

Utility functions to inline SVGs in PHP Projects

```
composer require 'vierwd/svg-inliner'

```

This library can be used to inline SVGs in PHP project. It processes the SVGs and changes some of the content:

- `fill="transparent"` should be `fill="none"`
- Short-close tags can be problematic in IE 9. That's why `` becomes ``.
- Comments are removed
- class-attributes are added on SVG-element with the filename as the class-name

It's also possible to combine SVGs and only output `` tags, which reference an SVG. This makes sense, if one SVG is used multiple times. But you loose the ability to style each tag individually.

Usage
-----

[](#usage)

```
$svgInliner = new SvgInliner($defaultOptions);

// render a single SVG file and output a -tag
$output = $svgInliner->renderSVGFile($pathToSvgFile, $options);

// render all SVGs which are references by -tags
$allSVGs = $svgInliner->renderFullSVG();

// render a single SVG and output directly
$output = $svgInliner->renderSVGFile($pathToSvgFile, ['excludeFromConcatenation' => true]);
```

Options
-------

[](#options)

- `excludeFromConcatenation`: output the SVG directly instead of the ``-tag. Available as default option in constructor. Defaults to false.
- `ignoreDuplicateIds`: Do not throw an exception when two SVGs use the same id-attributes. Available as default option in constructor. Defaults to false.
- `removeComments`: Remove all XML-comments. Available as default option in constructor. Defaults to true.
- `identifier`: Identifier for the SVG. If the same identifier is used, the file will not be loaded again, but used from cache. Defaults to the lowercase filename (with special chars transformed to dash.)
- `width`: Width attribute for SVG. Defaults to none and will leave attribute as-is.
- `height`: Height attribute for SVG. Defaults to none and will leave attribute as-is.
- `class`: Additional classes for SVG-tag. By default `.svg` and `.svg-identifier` are added.
- `external`: Embed the SVG as external ``-tag.
- `url`: URL for the `external` SVG

External SVGs
-------------

[](#external-svgs)

It is possible to include SVGs as links to external SVG files:

```
$svgInliner = new SvgInliner($defaultOptions);

// render a single SVG file and output a -tag with an external file
$output = $svgInliner->renderSVGFile($pathToSvgFile, [
	'external' => true,
	'url' => '/static/test.svg',
]);
```

**Output:**

```

```

This allows to style *some* parts of the SVG using CSS, but allows for the SVG to still be cachable. You can use `fill` and `stroke` for all parts of the SVG which do *not* have fill or stroke set. You can use `color` to set the color which is used as `currentColor` within the SVG.

**Attention:**

- IE 11 does not support external SVGs in ``-tags. You need to use a polyfill like [svgxuse](https://github.com/Keyamoon/svgxuse), if you need IE 11 support.
- The SVG needs a tag with an `id` attribute. If the `url` option does not contain a `#hash`, SvgInliner automatically uses the first ID it finds within the SVG. If no ID is found, an exception is thrown.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity76

Established project with proven stability

 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 ~258 days

Recently: every ~243 days

Total

7

Last Release

1286d ago

PHP version history (4 changes)1.0.0PHP &gt;=5.5.0

1.3.0PHP &gt;=7.2.0

1.4.0PHP &gt;=7.4.0

1.4.1PHP ^7.4.0 | ^8.0 | ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/31570fd9995c0f4bd2046957d8e043e8160b8acbfbb53ce560059f73fed7e4e6?d=identicon)[rvock](/maintainers/rvock)

---

Top Contributors

[![rvock](https://avatars.githubusercontent.com/u/209159?v=4)](https://github.com/rvock "rvock (38 commits)")

---

Tags

htmlsvginline

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[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)[spatie/laravel-html

A fluent html builder

8376.4M72](/packages/spatie-laravel-html)[caxy/php-htmldiff

A library for comparing two HTML files/snippets and highlighting the differences using simple HTML.

21320.9M15](/packages/caxy-php-htmldiff)[yajra/laravel-datatables-html

Laravel DataTables HTML builder plugin

2899.6M48](/packages/yajra-laravel-datatables-html)[voku/html-min

HTML Compressor and Minifier

1804.7M39](/packages/voku-html-min)[mkalkbrenner/php-htmldiff-advanced

An add-on for the php-htmldiff library for comparing two HTML files/snippets and highlighting the differences using simple HTML.

3517.8M1](/packages/mkalkbrenner-php-htmldiff-advanced)

PHPackages © 2026

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