Nodes/ComfyUI-ToSVG/SVG String Path Simplify
ComfyUI Node

SVG String Path Simplify

Shrink a bloated SVG without redrawing it

By Yanick112·Created 2 years ago·Updated about a year ago· 314
SVG String Path Simplify
    • STRING
    ◄SVG_String—►
    â—„tolerance5.0â–º
    â—„preserve_curvesfalseâ–º

    If you've traced a few images with this pack, you know the failure mode: the SVG comes out technically gorgeous and practically enormous. TS_SVGPathSimplify is the cleanup pass - it takes an SVG string and strips points out of the paths so the file shrinks, without you going back and retracing the whole thing.

    It landed in the June 17 update alongside the BytesIO bridge nodes, and it's a quiet quality-of-life win. You trace once with high accuracy, simplify the result, and get the best of both: faithful shapes, small file.

    How it works

    It's the Douglas–Peucker algorithm, the classic line-simplification trick: draw a line between a path's start and end, find the point farthest from it, and keep it if it's beyond the tolerance - then recurse on both halves. Points that don't matter get dropped, and the path is rebuilt. Internally it parses the SVG's <path> d attributes, extracts the coordinates, simplifies, and rewrites them as straight-line (M/L) segments.

    Here's the honest tradeoff: this implementation rebuilds simplified paths as straight lines. For traced splines that means curves become polygons. That's exactly what you want for laser cutting, vinyl cutting, and plotting, and usually fine for icons. It's a lossier operation than you'd want for fine curves, which is where preserve_curves comes in.

    Inputs and outputs

    • SVG_String - the SVG markup you want slimmed.
    • tolerance - 0.1 to 50, default 5. How much deviation you'll tolerate from the original line. Higher = smaller file, coarser result. Start at 5, and if shapes start losing detail, dial it down to 2–3.
    • preserve_curves - when on, the node keeps the original path if the simplification wouldn't reduce it meaningfully, so you don't destroy curves for tiny savings.
    • Output: the simplified STRING - pipe it into TS_SVGStringPreview to check, then TS_SaveSVGString to write the file.

    It also prints a "points reduced" percentage to the console, which is a nice reality check on whether the pass actually did anything.

    When to reach for it

    The sweet spot is file-size work: preparing traced art for web use, sending SVG to a plotter that chokes on 20k-point paths, or making a logo small enough to inline. If you're already getting clean traces, you can also be lazy on purpose - trace with accuracy, then simplify hard and let the algorithm find the waste.

    Install

    Same pack install as everything else here. ComfyUI Manager → search ComfyUI-ToSVG → Install → restart, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Yanick112/ComfyUI-ToSVG/
    cd ComfyUI-ToSVG
    pip install -r requirements.txt
    

    Dependencies: vtracer, numpy, Pillow, torch, PyMuPDF, potracer. No models, no keys, CPU-only. It sits under 💎TOSVG/Tools.

    Category💎TOSVG/Tools

    Inputs (3)

    NameTypeDefaultDescription
    SVG_StringSTRING—
    toleranceFLOAT5.00.1–50—
    preserve_curvesBOOLEANfalse—

    Outputs (1)

    NameTypeDescription
    STRINGSTRING—