Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Converts PNG images into a beautiful SVG vector graphic. Specially suited for small bitmaps / sprite images.
Latest commit d0ce9db @cesarmiquel Change image link
The old image link sample was dead. This points to an image in Tumblr. Not sure the URL will live4ever.
Failed to load latest commit information. Change image link
png2svg.php Initial version


This is a small project that converts a PNG file into an SVG image. For each pixel in the PNG we generate a square in the SVG canvas colored with the same color of the pixel and a border with a color which is slighly lighter. At the bottom of the image a palette is also created to show all the different colors used in the bitmap. It is designed to take a small bitmap and generate a large SVG representation of it.

To see what it does look here:

About the script

The script is short and written in PHP. It takes a single argument which must be a PNG file and outputs to standard out an SVG image. If I want to convert the file mario.png to SVG all I need to do is:

$ php png2svg.php mario.png > mario.svg

You can open the resulting image with Inkscape. The sample output looks like this:

Sample output

The only requirement is that PHP must be compiled with GD support.

Something went wrong with that request. Please try again.