After so many attempts, being just a hobby programmer, I've managed to make an extension which I hope would be useful. It's a Low Poly Trace where you can create a Delaunay diagram from paths (instead of from objects as in the Voronoi extension), as well as a color tracing option (!). It does depend on voronoi.py in extensions folder and uses some code from voronoi2svg.py which I modified, so thank you to the authors there (I've attributed them in the code comments). The main hurdles were (1) getting the correct area coordinates to export the traced image (once I understood the conversion between user and viewport units, it was surprisingly easy and doesn't use that many lines) (2) trying to wrangle the group transform and path transform to get the points to behave correctly.
Please try it out at https://gitlab.com/scribbleed1/lowpolytrace. I'm using Inkscape 1.2 on Windows 11. I think it would work on other OS but I think the unit_to_viewport method is only avaible from 1.2 onwards, so I don't think it will work on 1.1 or less. I've played around with various units to see if it exports and draw the points exactly, but I am not sure if it would work in every scenario. So do try it out to see if it correctly picks the underlying color. You may use the color reference code, in fact, please improve on it. There is no live-preview because a temporary file is created during the execution.
---- Low Poly Trace This extension will create a low poly diagram using Delaunay triangulation. Selection must include at least one path, and in total, at least 3 distinct points. Objects, Text or Paths in Groups in selection will be ignored. Paths can be combined (but not grouped) for ease of selection. If grouped, then enter the group and select the paths before starting the extension. Fill: Default fill and stroke color of each triangle is picked at the midpoint from the underlying drawing. If there are no objects at the location, the default page color or white will be used. If fill option is not selected, only black outlines will be drawn with no fill. Range: Points nearby within the specified range will be ignored so that narrow or small triangles will not be created. Exact duplicates are automatically ignored.
Usage
Requires Inkscape 1.2+ (uses unit_to_viewport method) [tested on Windows 11] Requires voronoi.py in Inkscape's program extension folder, which comes with the regular Inkscape installation Save lowpolytrace.inx and lowpolytrace.py to your user extension folder, e.g. C:\Users\Username\AppData\Roaming\Inkscape\extensions Extension will appear in Extensions -> Generate from Path -> Low Poly Trace... menu in Inkscape
Thank you for testing it out. Since I can't acces a Mac, I just looked through Inkscape's extensions to see how tempfile is referred. There is one in layer2png.py using mkstemp() which I remembered I didn't quite like because the temporary file was not removed after the extension ends - that's why I thought TemporaryDirectory() was a better choice. Using NamedTemporaryFIle() is not possible because it doesn't work with PIL on my Windows system. Anyway, I'll use mkstemp(), but add a close and remove so that the file doesn't stay in the system.
Please download lowpolytrace_1.py from https://gitlab.com/scribbleed1/lowpolytrace , rename and overwrite it over lowpolytrace.py. Try it out and if you can, check that the temporay file is removed (somewhere in /tmp, /var/tmp or /usr/tmp ?). If it works, I'll update it as the main extension file.
After confirming it seems Inkscape crashes - log pops up - but it´s still running. Then:
I can´t find the tmp files listed in the traceback message. Not sure how to help. Still could be user error? Load raster image - draw some Bézier lines - select all - call extension - proceed as per above.
That's odd. There shouldn't be a dialog for "SVG Input" - I really don't know why the command call would produce that in your case. If the temp file was not created, that could be reason for PIL not finding the file.
After googling, this might be something similar to this: https://gitlab.com/inkscape/inbox/-/issues/7056. You could try the steps there. Another way to check is to run the Extensions -> Export -> Export Layer Slices... (you have to first create a Layer called slices and draw at least one Rectangle in it). It does a similar command call and also shouldn't open an "SVG Input" dialog.
Other than that, I could only appeal to other users here for help.
Hello fellow Inkscapers,
After so many attempts, being just a hobby programmer, I've managed to make an extension which I hope would be useful. It's a Low Poly Trace where you can create a Delaunay diagram from paths (instead of from objects as in the Voronoi extension), as well as a color tracing option (!). It does depend on voronoi.py in extensions folder and uses some code from voronoi2svg.py which I modified, so thank you to the authors there (I've attributed them in the code comments). The main hurdles were (1) getting the correct area coordinates to export the traced image (once I understood the conversion between user and viewport units, it was surprisingly easy and doesn't use that many lines) (2) trying to wrangle the group transform and path transform to get the points to behave correctly.
Please try it out at https://gitlab.com/scribbleed1/lowpolytrace. I'm using Inkscape 1.2 on Windows 11. I think it would work on other OS but I think the unit_to_viewport method is only avaible from 1.2 onwards, so I don't think it will work on 1.1 or less. I've played around with various units to see if it exports and draw the points exactly, but I am not sure if it would work in every scenario. So do try it out to see if it correctly picks the underlying color. You may use the color reference code, in fact, please improve on it. There is no live-preview because a temporary file is created during the execution.
----
Low Poly Trace
This extension will create a low poly diagram using Delaunay triangulation.
Selection must include at least one path, and in total, at least 3 distinct points. Objects, Text or Paths in Groups in selection will be ignored. Paths can be combined (but not grouped) for ease of selection. If grouped, then enter the group and select the paths before starting the extension.
Fill: Default fill and stroke color of each triangle is picked at the midpoint from the underlying drawing. If there are no objects at the location, the default page color or white will be used. If fill option is not selected, only black outlines will be drawn with no fill.
Range: Points nearby within the specified range will be ignored so that narrow or small triangles will not be created. Exact duplicates are automatically ignored.
Usage
Requires Inkscape 1.2+ (uses unit_to_viewport method) [tested on Windows 11]
Requires voronoi.py in Inkscape's program extension folder, which comes with the regular Inkscape installation
Save lowpolytrace.inx and lowpolytrace.py to your user extension folder, e.g. C:\Users\Username\AppData\Roaming\Inkscape\extensions
Extension will appear in Extensions -> Generate from Path -> Low Poly Trace... menu in Inkscape
Unfortunately I got this message on macOS.
Could be user error.
Thank you for testing it out. Since I can't acces a Mac, I just looked through Inkscape's extensions to see how tempfile is referred. There is one in layer2png.py using mkstemp() which I remembered I didn't quite like because the temporary file was not removed after the extension ends - that's why I thought TemporaryDirectory() was a better choice. Using NamedTemporaryFIle() is not possible because it doesn't work with PIL on my Windows system. Anyway, I'll use mkstemp(), but add a close and remove so that the file doesn't stay in the system.
Please download lowpolytrace_1.py from https://gitlab.com/scribbleed1/lowpolytrace , rename and overwrite it over lowpolytrace.py. Try it out and if you can, check that the temporay file is removed (somewhere in /tmp, /var/tmp or /usr/tmp ?). If it works, I'll update it as the main extension file.
At first this opens:
After confirming it seems Inkscape crashes - log pops up - but it´s still running. Then:
I can´t find the tmp files listed in the traceback message. Not sure how to help. Still could be user error? Load raster image - draw some Bézier lines - select all - call extension - proceed as per above.
That's odd. There shouldn't be a dialog for "SVG Input" - I really don't know why the command call would produce that in your case. If the temp file was not created, that could be reason for PIL not finding the file.
After googling, this might be something similar to this: https://gitlab.com/inkscape/inbox/-/issues/7056. You could try the steps there. Another way to check is to run the Extensions -> Export -> Export Layer Slices... (you have to first create a Layer called slices and draw at least one Rectangle in it). It does a similar command call and also shouldn't open an "SVG Input" dialog.
Other than that, I could only appeal to other users here for help.