pyatt
pyatt

Reputation: 57

Converting a BMP/PNG/JPEG to an SVG file using Python

I'm currently trying to convert BMP files to SVG files using Python. I'm trying to find a Python library that will enable me to convert BMP/PNG/JPEG files to SVG files.

I've already tried using Potrace but the quality is awful. I need the end results to be fairly high-quality. I can't use online converters and must be able to do these conversions on my machine as I'm working with sensitive data.

Any suggestions would be greatly appreciated. Thank you!

Edit: I found out that I wasn't using the correct settings for Potrace in my testing. This is what yielded the "awful" result. Unfortunately, I've also learned that Potrace doesn't support color outputs. I've messed around with Inkscape and Vector Magic and I think they're my best bet at the moment.

Upvotes: 2

Views: 9826

Answers (1)

shubhamr238
shubhamr238

Reputation: 1408

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()

Upvotes: 2

Related Questions