enjeck / jpg2svg

Convert JPG images to SVG

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jpg2svg

An attempt at converting colored JPG images to colored SVG. It automatically traces the image in layers and applies dominant colors selected from the image to each layer.

Some results (JPG and converted SVG side by side)

Images with higher contrast, and with white backgrounds produce better results:

Technical details

The actual image conversion code is held at svg.py. Below is a summary of the steps it follows:

  • Resizes the image to reduce processing time
  • Quantitizes the image to reduce the number of colors to work with
  • Calculates the luminance/brightness of dominant colors
  • Converts the JPG image to bitmap (since Potrace, used for tracing, only supports the Bitmap format)
  • Uses luminance values as thresholds for tracing the image into multiple layers
  • Converts the tracing to XML
  • Applies dominant colors to each of the layers
  • Groups the various layers into one SVG element

About

Convert JPG images to SVG


Languages

Language:Python 28.3%Language:JavaScript 28.2%Language:HTML 27.0%Language:CSS 16.6%