2025-03-29 20:51:05 +01:00
2025-03-29 20:51:05 +01:00
2025-03-28 02:18:27 +01:00
2025-03-29 20:51:05 +01:00
2025-03-29 20:51:05 +01:00
2025-03-29 20:51:05 +01:00
2025-03-28 02:18:27 +01:00

UNofficial ComfyUI Potrace(r) SVG conversion

This is my First ever (public) ComfyUI node. While tested thoroughly, and as with all custom nodes, USE AT YOUR OWN RISK.

I created this custom node because i wasn't getting the results I wanted when using the ComfyUI-ToSVG node by Yanick112. This is NOT a complaint; his work is great and inspired me.
ComfyUI-toSVG implements the VTracer logic, and this works great for multicolor and detailed images.
For logo's, text, etc. I found Potrace SVG conversion better suited, with the caveat that it only handles 2 colors; a Foreground and Background.
I also found Potrace better more optimized shapes with less points and thus requires less to no cleanup when loading into vector design software.

Potracer to SVG node traces a raster image (IMAGE) into an SVG vector graphic using the 'potracer' pure Python library for POTRACE.

Comparing Vtracer and Potracer

While each user and route will have their specific usecase, my usecase is creating designs for Vinylcutters and logo's. This usecase requires sharp images, fluid shapes and clear separation of fore and background.

Vtracer vs Potracer

  • Left side: Vtracer (Green, Top) shows significantly more artifacts, hard edges or straight lines, and irregular traces compared to Potracer (Blue, Bottom), which stays true to the original form.
  • Right side: Vtracer has significantly more vector points compared to the optimized Potracer version.
  • For the usecases where Vtracer suits best, go check out (https://github.com/Yanick112/ComfyUI-ToSVG/), where Yanick explains the workings in detail.

Installation

Due to both usecases for SVG export are very valid when working with ComfyUI, I opted to keep the naming and category alike for easier navigation.

note: This node requires Yanick112's ComfyUI-ToSVG --> SaveSVG node to save the SVGfile. See his repository for install instructions

  1. Navigate to your /ComfyUI/custom_nodes/ folder.

  2. Run the following command to clone the repository:

    git clone https://github.com/ImagineerNL/ComfyUI-ToSVG-Potracer

  3. Navigate to your ComfyUI-ToSVG-Potracer folder.

    • Command for Portable/venv:

        path/to/ComfUI/python_embeded/python.exe -s -m pip install -r requirements.txt
      
    • Command for system Python:

        pip install -r requirements.txt
      

Enjoy setting up your ComfyUI-ToSVG tool! If you encounter any issues or need further help, feel free to reach out.

Usage

The input image should only use the two colors black and white. If other pixel values appear in the input, they will be converted to black and white using a simple threshold method. Outputs svg strings as 1 flat shape (as a compound path). Should you want to adjust the shapes by hand, currently, when you release the path in vector design software, the 'internal openings' become filled shapes. This is easy to fix using the boolean tools and substract. My main usecase is Silhouette Studio for vinylcutting and especially with 'zero_sharp_corners' set to true, i don't need to do any postprocessing on the shape.

alt text

Parameter Usage Default
threshold Brightness cutoff (0-255) for binarization to B/W. 128
input_foreground Defines if the input image is a Black object on White background or White on Black background Black on White
turnpolicy How to resolve ambiguities in path decomposition minority
turdsize Suppress speckles of up to this many pixels 2
corner_treshold Smaller values = sharper corners 1
zero_sharp_corners Forces al corners to be fluid. (same as corner_treshold = 1.34) false
opttolerance Curve optimization tolerance 0.2
optimize_curve Curve optimization, joins adjacent Bezier curve segments where possible. Reduces filesize and points true
foreground_color Defines foreground color after trace #rrggbb #000000
stroke_color Defines stroke color after trace #rrggbb #ff0000
stroke_width Sets a stroke width/outline for the traced shapes 0.0
background_color Defines background color after trace #rrggbb #ffffff
no_background Removes the background color. false
Output
svg_strings a list of strings to be converted to svg shape.
Note: Requires ComfyUI-ToSVG --> SaveSVG to save the SVGfile.

Workflow

alt text
The above image is just a visualisation, does not contain workflow
ComfyUI_ToSVG_Potrace_Workflow.png
drag/drop in ComfyUI
Example Workflow JSON
Example Workflow PNG

Tested on

The node is model independent, but I'm getting great results using:

Sources, Shoutouts, Love and Inspiration

To Do

  • Deploy V1 to Github
  • Real life testing & feedback
  • Deploy to Comfyregistry

Disclaimer

While tested a lot and I have IT knowledge, I am no programmer by trade. This is a passion project for my own specific usecase and I'm sharing it so other people might benefit from it just as much as i benefitted from others. I am convinced this implementation has its flaws and it will probably not work on all other installations worldwide. I can not guarantee if this project will get more updates and when.

S
Description
No description provided
Readme
3.4 MiB
Languages
Python 100%