Is there a way to convert pixel art into vector?


I've made some high resolution pixel art in PS by drawing it down at the pixel level and then increasing the image size with the nearest neighbor setting to keep it crisp. In the web browser, however, I need to display these images as icons with a dynamic size, so I can't just size the images correctly to begin with, and the broswer seems to blur the images when rendering them smaller, while vector images seem to stay more crisp as they shrink.

So I'm wondering if there's a way to convert the pixel art neatly into vector. I'm aware of the trace function in illustrator, but it seems to do a rough job iirc.

10/25/2016 1:24:00 AM

Accepted Answer

Browser rendering

You can use the CSS property image-rendering to stop browsers from applying anti-aliasing and interpolating your image when resized. Browser support is a bit inconsistent though. Some browsers support the pixelated value while others need the crisp-edges value. Internet Explorer instead uses the non-standard -ms-interpolation-mode: nearest-neighbor and Edge apparently has no support at all. Putting it all together you'd need something along the lines of:

.icon {
    image-rendering: -webkit-crisp-edges;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    -ms-interpolation-mode: nearest-neighbor;

You can read more here: CSS-Tricks: image-rendering and see specifics on browser support at caniuse here: Can I use... Crisp edges/pixelated images.


You could use the object mosaic function in Illustrator to convert your pixel art to vectors. This will end up with a bigger file but whether that is too big depends on your requirements and the artwork itself. Take this 30 × 30 pixel smiley face I just drew:

enter image description here

This is the resulting mosiac:

enter image description here

Now, we don't need all of those individual tiles so we can merge a lot of them in to single shapes (using Pathfinder) saving on some of that increased file size. Even similarly colored tiles that aren't connected can be converted to compound paths which would save you a bit of file size. This obviously depends on the artwork itself though.

After merging some of our tiles:

enter image description here

The rusulting SVG (without any optimization) was about 10KB which, although a significant amount bigger than the 4KB the original PNG was, still isn't very big.

10/25/2016 4:13:00 PM

Automatic tracing is possible, but only works for very specialized cases. Having lots of detail or intertwining shapes is poison for a tracing algorithm. In reality if you wish to have a quality vector image you will have to draw that vector image yourself.

For pixel art its possible that you could do a image mosaic (which would always work), then tell svg not to antialias. However this will create a HUGE file and its possible to use other solutions to make the browser not interpolate images with some higher order fliter.