Convert PNG to SVG using python

帅比萌擦擦* 提交于 2019-12-04 09:56:40

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

chrarndt

I'm using https://github.com/ianmackinnon/png2svg to convert low resolution QR-Codes to SVG to print them in arbitrary sizes. It works pretty well, the codes look as expected and are scalable to arbitrary sizes.

However, 2 small (but negligible, at least for me) caveats:
- Conversion takes about a minute or so on my machine for a low resolution image (400x400)
- The file sizes are larger than they should be, compared to an optimized SVG

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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!