PHPackages                             kartsims/easysvg - 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. kartsims/easysvg

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

kartsims/easysvg
================

PHP library to generate SVG XML

2.5(3y ago)101424.2k↑12.4%45[4 PRs](https://github.com/kartsims/easysvg/pulls)1MITPHPPHP &gt;=7.4.0

Since Jul 12Pushed 2y ago5 watchersCompare

[ Source](https://github.com/kartsims/easysvg)[ Packagist](https://packagist.org/packages/kartsims/easysvg)[ Docs](https://github.com/kartsims/easysvg)[ RSS](/packages/kartsims-easysvg/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (1)

EasySVG for PHP
===============

[](#easysvg-for-php)

Generate SVG images from SVG font easily.

The SVG data produced here is directly extracted from the font .svg file. This **does not use the &lt;text&gt; tag**.

Simple usage
------------

[](#simple-usage)

```
require 'easySVG.php';

$svg = new EasySVG();
$svg->setFont("om_telolet_om-webfont.svg", 100, '#000000');
$svg->addText("Simple text display");
$svg->addAttribute("width", "800px");
$svg->addAttribute("height", "120px");
echo $svg->asXML();
```

Advanced usage
--------------

[](#advanced-usage)

```
require 'easySVG.php';

$text = "Simple text display\netc.";

$svg = new EasySVG();
$svg->setFontSVG("om_telolet_om-webfont.svg");
$svg->setFontSize(100);
$svg->setFontColor('#000000');
$svg->setLineHeight(1.2);
$svg->setLetterSpacing(.1);
$svg->setUseKerning(true);
$svg->addText($text);
// set width/height according to text
list($textWidth, $textHeight) = $svg->textDimensions($text);
$svg->addAttribute("width", $textWidth."px");
$svg->addAttribute("height", $textHeight."px");
echo $svg->asXML();
```

This will output inline SVG for you to play with. You can **echo** it, **save** it to a file or whatever.

Method reference
----------------

[](#method-reference)

#### setFont($path, $size, $color = null)

[](#setfontpath-size-color--null)

Sets the font attributes. This is a shortcut for :

```
$this->setFontSVG($path);
$this->setFontSize($size);
$this->setFontColor($color);
```

These 3 methods are explicit enough, I won't go through these in here.

#### setUseKerning($bool)

[](#setusekerningbool)

Use SVG font [kerning](https://en.wikipedia.org/wiki/Kerning) pairs. Default is `false`.

#### setLineHeight($value)

[](#setlineheightvalue)

Adds a CSS-like line-height value. A numeric value (float) where 1 is the line height defined by the font itself.

#### setLetterSpacing($value)

[](#setletterspacingvalue)

Adds a CSS-like letter-spacing value. A numeric value (float) expressed in em where 1 is the width of the `m` character.

#### addText($text, $x, $y, $attributes=array())

[](#addtexttext-x-y-attributesarray)

Add text to the SVG (will be converted to simple path)

- `$text` : String UTF-8 encoded
- `$x` : X position of the text (starting from left), can be `center` to center the text horizontally
- `$y` : Y position of the text (starting from top), can be `center` to center the text vertically
- `$attributes` (optional) : list of tag attributes

#### asXML()

[](#asxml)

Return XML string of the whole SVG.

#### addAttribute($key, $value)

[](#addattributekey-value)

Add an attribute to the main SVG.

### SVG data manipulation methods

[](#svg-data-manipulation-methods)

You may need these to play around with SVG definitions.

#### defTranslate($def, $x=0, $y=0)

[](#deftranslatedef-x0-y0)

Applies a translate transformation to a definition. This basically applies matrix calculation to a definition.

#### defRotate($def, $angle, $x=0, $y=0)

[](#defrotatedef-angle-x0-y0)

Applies a translate transformation to definition. This basically applies matrix calculation to a definition.

#### defScale($def, $x=1, $y=1)

[](#defscaledef-x1-y1)

Applies a scale transformation to definition. This basically applies matrix calculation to a definition.

#### textDef($text)

[](#textdeftext)

Returns a SVG-formatted definition of a string. This method is used by addText method.

- `$text` : String UTF-8 encoded

#### textDimensions($text)

[](#textdimensionstext)

Returns the width and height of a string. This method is also used to set the width/height of the SVG (if none specified).

- `$text` : String UTF-8 encoded

#### unicodeDef($code)

[](#unicodedefcode)

Returns a SVG-formatted definition of an unicode character.

- `$code` : Unicode definition (in hex format)

#### characterWidth($char, $is\_unicode=false)

[](#characterwidthchar-is_unicodefalse)

Returns the width of a character.

- `$char` : Character
- `$is_unicode` : Boolean that tells if the character is a unicode string or a UTF-8 character.

#### addPath($def, $attributes=array())

[](#addpathdef-attributesarray)

Add a path to the SVG data

- `$def` : SVG definition
- `$attributes` (optional) : list of tag attributes

### Utility methods

[](#utility-methods)

#### clearSVG()

[](#clearsvg)

Resets the SVG data. Used to start a new SVG without creating a new instance.

#### defApplyMatrix($def, $matrix)

[](#defapplymatrixdef-matrix)

Apply a matrix to a definition. Used to apply any kind of transformations, you shouldn't need this, but it is available so you may play with it.

License
-------

[](#license)

MIT. Please feel free to pull, fork, and so on.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity54

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 56.3% 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 ~861 days

Total

3

Last Release

1145d ago

Major Versions

1.0 → 2.42022-02-21

PHP version history (2 changes)1.0PHP &gt;=5.3.0

2.4PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ea436f1f084470f9d75ca0fde95e2418ba03d560bc4e20e03171648c123fa80?d=identicon)[ricardoboss](/maintainers/ricardoboss)

![](https://www.gravatar.com/avatar/79580db64b8d54499807d85b2a79a2d4d657ae4628c99c8efdc57481787ce956?d=identicon)[nvashenko](/maintainers/nvashenko)

![](https://www.gravatar.com/avatar/723468036a7f6f9b334e98cdd3fa28eea337ffca8ea2fe2c8c22476b55815518?d=identicon)[kartsims](/maintainers/kartsims)

---

Top Contributors

[![kartsims](https://avatars.githubusercontent.com/u/4136975?v=4)](https://github.com/kartsims "kartsims (27 commits)")[![ricardoboss](https://avatars.githubusercontent.com/u/6266356?v=4)](https://github.com/ricardoboss "ricardoboss (8 commits)")[![joewhitsitt](https://avatars.githubusercontent.com/u/4663676?v=4)](https://github.com/joewhitsitt "joewhitsitt (3 commits)")[![mrk-j](https://avatars.githubusercontent.com/u/1250622?v=4)](https://github.com/mrk-j "mrk-j (3 commits)")[![greendrake](https://avatars.githubusercontent.com/u/1991299?v=4)](https://github.com/greendrake "greendrake (2 commits)")[![splitbrain](https://avatars.githubusercontent.com/u/86426?v=4)](https://github.com/splitbrain "splitbrain (1 commits)")[![ppelisset](https://avatars.githubusercontent.com/u/954371?v=4)](https://github.com/ppelisset "ppelisset (1 commits)")[![rac2030](https://avatars.githubusercontent.com/u/294207?v=4)](https://github.com/rac2030 "rac2030 (1 commits)")[![smartman](https://avatars.githubusercontent.com/u/1007410?v=4)](https://github.com/smartman "smartman (1 commits)")[![Franzz](https://avatars.githubusercontent.com/u/298765?v=4)](https://github.com/Franzz "Franzz (1 commits)")

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/kartsims-easysvg/health.svg)

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

PHPackages © 2026

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