EmbroidePy / pyembroidery

pyembroidery library for reading and writing a variety of embroidery formats.
MIT License
195 stars 35 forks source link

Rendering #30

Closed ekw closed 6 years ago

ekw commented 6 years ago

Can this module render supported embroidery files to JPG/PNG?

tatarize commented 6 years ago

Currently, no. But, that's not actually that hard to do. It does allow you to quickly convert them to .svg which more than a few packages will easily turn into JPG/PNG, and many will let you display them pretty directly. I tried to minimize the amount of external modules and kept it zero, and limit it to python internals at most and there wasn't an obvious internal JPG/PNG writer in python.

Obviously there's a pretty significant bit of utility in producing images of the embroidery as well as thumbnails. I could code up the functionality quite quickly using a 3rd party requirement like PIL, the code would basically just need to import pyembroidery and something like PIL then draw the colored lines on a canvas and export the graphics file. Basically the same code as the svg writer currently does, but putting those lines to a canvas rather than an xml. Adding it to something like the pyembroidery-CLI tools wouldn't be an issue.

tatarize commented 6 years ago

Actually I checked and found a recipe for a pure python png writer. Obviously it didn't have a canvas or line draw algorithm but, I wrote a copy of bresenham line draw algorithm a few years back and ported my code from there and added that in. So it now outputs 32-bit png with a write_png() command. So it didn't when you asked, but it does now.

If you need it on PyPI I could push it along. Though, it might need some other stuff depending on your usecase. the latest version is in master: 1.3.1

ekw commented 6 years ago

Wow, thanks! I just tried it and it works great.

tatarize commented 6 years ago

Updated with a couple super basic options and pushed it to pypi.