Converts PNG images into a beautiful SVG vector graphic. Specially suited for small bitmaps / sprite images.
Latest commit d0ce9db Sep 7, 2013 @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 Sep 7, 2013
png2svg.php Initial version Nov 22, 2011


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.