SVG Path Cleanup
Make your vector file small, smooth, and actually usable
- cleaned_svg
- statistics
Raw vectorized line art is a hoarder's closet. Every dust speck becomes a path, every doubled edge becomes two nearly-identical paths, and every contour is carrying far more points than it needs. SVG Path Cleanup is the Marie Kondo pass for your SVG: it runs a battery of fixes on the path data itself and hands you back a smaller, cleaner, more machine-friendly file. The README's performance tip says it plainly - for large SVGs, use this to reduce path count.
What it cleans, one toggle at a time
All the toggles default on, which is the right call:
remove_short_paths/min_path_length(default 5) - deletes paths shorter than this. Your speck-killer. If you set it to 0, nothing gets removed by length.merge_close_paths/merge_distance(default 2) - joins paths whose endpoints sit within this distance, so the same line broken into fragments by the contour finder becomes one continuous path. This is a big one for laser-cutters and plotters, where a broken line means a lift of the head mid-stroke.simplify_paths/simplify_tolerance(default 0.5) - Douglas-Peucker simplification on each path. This is what actually shrinks your file: it drops points that aren't pulling their weight. Tolerance 0.5 is a good starting balance; push it up for aggressive reduction.remove_near_duplicate_paths/near_duplicate_distance(default 1.5) - the interesting one. It treats two paths as duplicates if their bidirectional average distance is below the threshold, then drops one. That's the fix for the double-line problem at the SVG level (Mask Line Cleanup handles it at the pixel level, before tracing).round_coordinates/decimal_places(default 2) - rounds path coordinates so your SVG is human-readable and smaller. Feed a 15-decimal-point path into a plotter and it'll thank you.remove_duplicate_paths(optional, default on) - exact-duplicate removal on top of the near-duplicate pass.
Outputs: cleaned_svg (feed onward to the savers or style nodes) and statistics (JSON - how many paths removed, merged, simplified; the number you'll actually care about).
Where it sits in the pipeline
The pack's own reference flow is: Line Region Detector → Centerline to SVG → SVG Path Cleanup (optional) → SVG File Saver. It's the same cleanup philosophy as Mask Line Cleanup, but one stage later and on geometry instead of pixels. Run it before saving and before auto-reorder - a cleaned, merged, simplified SVG reorders more predictably and is far easier to style by index, because stray duplicate paths aren't inflating your path numbers.
Install
The whole pack installs together:
cd ComfyUI/custom_nodes
git clone https://github.com/TJ16th/TJ_ComfyUI_Lineart2Vector.git
# restart ComfyUI
or ComfyUI Manager → search TJ_ComfyUI_Lineart2Vector. No models, no keys. It imports numpy/opencv/scipy from the pack's requirements.txt - all stock ComfyUI territory, so a bare clone usually just works.
Where people get burned
The trap is over-cleaning: crank simplify_tolerance too high and fine details - eyelashes, hair strands, thin accent lines - round away into smooth blobs. And merge_close_paths with a generous merge_distance can weld together paths that were supposed to be separate (a closed loop snapped shut, two unrelated lines joined). Check the statistics output and, more importantly, spot-check visually with SVG To Image or SVG Group Layout after cleaning. And note the difference between min_path_length (removes short) and min_component_size on the mask-side node - different stages, both useful, don't confuse their job.
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| svg_string | STRING | — | |
| remove_short_paths | BOOLEAN | true | — |
| min_path_length | FLOAT | 5.00–100 | Remove paths shorter than this length |
| merge_close_paths | BOOLEAN | true | — |
| merge_distance | FLOAT | 2.00–20 | Merge paths if endpoints are within this distance |
| simplify_paths | BOOLEAN | true | — |
| simplify_tolerance | FLOAT | 0.50–5 | Path simplification tolerance |
| remove_near_duplicate_paths | BOOLEAN | true | — |
| near_duplicate_distance | FLOAT | 1.50–10 | Treat two paths as duplicates if their bidirectional average distance is below this threshold |
| round_coordinates | BOOLEAN | true | — |
| decimal_places | INT | 20–6 | — |
| remove_duplicate_pathsopt | BOOLEAN | true | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| cleaned_svg | STRING | — |
| statistics | STRING | — |