PHPackages                             msztorc/svg-convert - 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. [Image &amp; Media](/categories/media)
4. /
5. msztorc/svg-convert

ActiveLibrary[Image &amp; Media](/categories/media)

msztorc/svg-convert
===================

Various helpers to convert SVG files to other formats including PNG &amp; PDF.

1.0.0(7y ago)143.8k3MITPHP

Since Apr 26Pushed 6y ago2 watchersCompare

[ Source](https://github.com/msztorc/svg-convert)[ Packagist](https://packagist.org/packages/msztorc/svg-convert)[ RSS](/packages/msztorc-svg-convert/feed)WikiDiscussions master Synced today

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

[![Build Status](https://camo.githubusercontent.com/1961574c4a4705b07dbc729ab2d298cedd84fe1ffd9a452fa4da8c14a3120b52/68747470733a2f2f7472617669732d63692e6f72672f6d737a746f72632f7376672d636f6e766572742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/msztorc/svg-convert)[![License](https://camo.githubusercontent.com/30597ff9a350144f03bffdd9183e16468e0b3ca1193e1d08591d992622738d55/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](http://www.opensource.org/licenses/MIT)

[![svg-convert](https://camo.githubusercontent.com/0dedd78d1d68d3c426cce9f86b27296ca4ca52d7a8dd84ad1158461624097fc7/68747470733a2f2f737a746f72632e636f6d2f7376672d636f6e766572742f7376672d636f6e766572742e706e67)](https://camo.githubusercontent.com/0dedd78d1d68d3c426cce9f86b27296ca4ca52d7a8dd84ad1158461624097fc7/68747470733a2f2f737a746f72632e636f6d2f7376672d636f6e766572742f7376672d636f6e766572742e706e67)

svg-convert
===========

[](#svg-convert)

Various helpers to convert SVG files to other formats, especially PNG and PDF. Package includes CLI (phantomjs script) to render and php adapter to manipulate and convert SVG format using phantomjs or rsvg-convert (librsvg).

Install PhantomJS
-----------------

[](#install-phantomjs)

Before installing PhantomJS, you will need to install some required packages on your system. You can install all of them with the following commands:

`sudo apt-get update`

`sudo apt-get install build-essential chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 -y`

Next, you will need to download the PhantomJS. You can download the latest stable version of the PhantomJS from their official website.

`wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2`

Extract the downloaded archive file to desired system location:

`sudo tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/`

Next, create a symlink of PhantomJS binary file to systems bin directory:

`sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/`

### Use psvg-convert script globally

[](#use-psvg-convert-script-globally)

```
chmod +x src/js/psvg-convert.js
sudo cp src/js/psvg-convert.js /usr/local/bin/psvg-convert
```

Install RSVG (only if you want to convert svg using librsvg)
------------------------------------------------------------

[](#install-rsvg-only-if-you-want-to-convert-svg-using-librsvg)

`sudo apt-get update`

`sudo apt-get install libcairo2-dev libspectre-dev librsvg2-dev \ libpoppler-glib-dev librsvg2-bin`

Examples
--------

[](#examples)

#### Convert SVG to PNG format using PhantomJS CLI script

[](#convert-svg-to-png-format-using-phantomjs-cli-script)

`psvg-convert inputfile.svg outputfile.png`

##### Usage

[](#usage)

`psvg-convert svgfile outputfile [--width=800 --height=600 --zoom=2.5 --format=png|pdf]`

#### Convert SVG file in PHP

[](#convert-svg-file-in-php)

Initializing method with `phantomjs` argument when you want use to PhantomJS engine

```
$svg = (new SVG)->init('phantomjs');
```

or if you want to use rsvg-convert

```
$svg = (new SVG)->init('rsvg');
```

```
