Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert PNG to SVG using python

Is there way to convert a png file into SVG file using only pure python or a python module such as wand?

To be more precise, I want to convert a png into a real vector graphics, I don't want to embed a bitmap inside the svg, I want to convert into graphics code.

I know this is possible with Illustrator or Inkscape, but I need an automated process.

Thank you !

like image 328
marco Avatar asked Jul 15 '15 10:07

marco


2 Answers

You will need to run an external program to do the image tracing. A popular program is potrace. It is what Inkscape uses to perform the task.

There are some python bindings for it:

https://pypi.python.org/pypi/pypotrace

like image 188
Paul LeBeau Avatar answered Sep 19 '22 01:09

Paul LeBeau


I would suggest using potrace for python.
Use this link: https://pypi.org/project/pypotrace/
Here is the documentation: https://pythonhosted.org/pypotrace/ref.html#

Like This:

from potrace import Bitmap

# Initialize data, for example convert a PIL image to a numpy array
# [...]

bitmap = Bitmap(data)
path = bitmap.trace()
like image 28
shubhamr238 Avatar answered Sep 21 '22 01:09

shubhamr238