PNG from SVG with PHP

Because of the lack of support for SVG in current web browsers we need a solution for showing the users the icons within our project MAP-it.

The default GD library doesn’t support the SVG graphic format. We had to turn to Image Magick. If you are not allowed to execute on your webserver you can’t use the Image Magick Library from Linux. But you can always ask your webhost to install the iMagick php library which offers the same functionality without requiring exec() rights.

For testing purposes you can install iMagick php extension on your local webserver by following these instructions for windows and these instructions for mac.

Documentation for the iMagick library can be found here. Another very good example is from the creator of iMagick and can be read here.

We used the iMagick library in order to be able to view the users uploaded icon in every browser.

The image from the svg:

$image=new imagick();

where $file is the SVG path.

Copy from

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s