EmbroidePy / pyembroidery

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

added plotting of pattern #119

Closed SReich-EMI closed 3 years ago

SReich-EMI commented 3 years ago

added a function to directly plot the stitching pattern. Only reading out the color hex code I didn't find. Added therefore a TODO Would be nice if this could be added.

tatarize commented 3 years ago

There are no dependencies for pyembroidery. The only way this could be accepted is if the imports were put in the function and caught the import error within that function. I don't have a major objection to soft dependencies but hard dependencies aren't a thing that will ever be part of this library.

If you want to see this to a weird level look at the PNG writer, it's coded up barebones rather than half a dozen lines of Pillow referenced code.

tatarize commented 3 years ago
    from PIL import Image, ImageDraw
    extends = pattern.bounds()
    pattern.translate(-extends[0], -extends[1])
    width = int(extends[2] - extends[0])
    height = int(extends[3] - extends[1])
    draw_buff = Image.new('RGBA', (width, height))
    drawer = ImageDraw.Draw(draw_buff)
    for stitches, color in pattern.get_as_stitchblock():
        if len(stitches) == 0:
            continue
        b = [(q[0], q[1]) for q in stitches]
        drawer.line(b, fill=color.hex_color(), width=3)

The stitch block gives the color for that stitchblock too.