Nodes/ComfyUI_SVG-Suite/Advanced SVG Compression
ComfyUI Node

Advanced SVG Compression

SVG files too fat? This node actually shrinks them

By MushroomFleet·Created about a year ago·Updated 5 months ago· 9
Advanced SVG Compression
    • STRING
    ◄svg_string—►
    â—„compression_typesimplifyâ–º
    â—„curve_fidelity10â–º
    â—„pre_selectfalseâ–º
    â—„selection_criteriabboxareaâ–º
    â—„selection_threshold300.0â–º
    â—„optimize_aftertrueâ–º
    â—„delete_threshold100.0â–º
    â—„delete_criteriabboxareaâ–º
    â—„simplify_epsilon1.0â–º
    â—„merge_epsilon5.0â–º
    â—„buffer_distance5.0â–º
    â—„operation_keyhullâ–º

    Your vtracer SVG looks great, and then you open the file and it's 8 MB. Every traced shape is a polygon with thousands of points, and browsers choke on it. That's the exact problem Advanced SVG Compression exists for. It's the one node in svg-suite I'd argue everyone converting images to SVG should run before saving - a traced SVG without this step is like a PNG that was never optimized.

    What it actually does

    This node wraps the SVGCompress library, and it has three compression modes that target different bloat:

    • delete - drops tiny polygons below a size threshold. Great for removing the speckle noise that image tracing loves to leave behind.
    • simplify - the interesting one. It runs the Ramer-Douglas-Peucker algorithm over your paths, keeping the shape recognizable while cutting out redundant points. This is where most of your file-size wins come from, and it's the default for good reason.
    • merge - combines adjacent or overlapping shapes into single outlines, using either a convex hull or a boolean union.

    The distinction matters. Delete is surgical, simplify is the everyday workhorse, and merge is what you reach for when you have dozens of overlapping blobs that could be one clean shape.

    The inputs that matter

    You only touch a few of these on a normal day:

    • compression_type - delete / simplify / merge.
    • curve_fidelity - 1 to 50. How faithfully curves are preserved. Too low and things get angular; the default of 10 is a decent starting point.
    • selection_threshold - the size cutoff for selecting which polygons get worked on (measured by selection_criteria, either bboxarea or circumference).
    • optimize_after - default true, and leave it on. It runs a Scour cleanup pass after compressing, which is where you pick up the last bits of savings.

    The optional inputs only matter per-mode: simplify_epsilon controls how aggressive the RDP simplification is (higher = smaller and rougher), merge_epsilon and buffer_distance tune merge behavior, and delete_threshold sets what counts as "tiny" for delete mode.

    Output is a single STRING - the compressed SVG markup, ready to pipe into SVG Optimize (Scour) or SVG Preview (Advanced).

    Install

    This is a shared svg-suite node, so install is the same as the rest of the pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MushroomFleet/svg-suite
    cd svg-suite
    pip install -r requirements.txt
    

    Then restart ComfyUI. On Windows portable, the repo ships an install-portable.bat that targets the python_embeded interpreter. Or just use ComfyUI Manager and search "svg-suite". The heavy dependencies here are SVGCompress and its friends shapely, rdp, and svg.path - they're all in requirements.txt, so a Manager install pulls them automatically.

    Where people get burned

    The most common issue is expecting miracles. Compression is a quality/size trade, and cranking curve_fidelity to 1 or simplify_epsilon to 20 will absolutely wreck a logo into a blob. Go iterative: run it at defaults, check the preview, nudge down only what looks bad.

    Second gotcha: if SVGCompress isn't installed, the node doesn't error - it just returns your original SVG unchanged with a console message. That's the kind of silent failure that makes you think the node "isn't working" when it's actually a missing dependency. Check your console, and check that shapely and rdp came along.

    Also worth knowing: this operates on the SVG as a string, which is how all the svg-suite string nodes work - feed it the STRING output of a conversion node, not an image. If you're feeding it an IMAGE you've wired up wrong.

    Category💎TOSVG/Advanced

    Inputs (13)

    NameTypeDefaultDescription
    svg_stringSTRING—
    compression_typeCOMBOsimplify3 options: delete, simplify, merge
    curve_fidelityINT101–50—
    pre_selectBOOLEANfalse—
    selection_criteriaCOMBObboxarea2 options: bboxarea, circumference
    selection_thresholdFLOAT300.00.1–10000—
    optimize_afterBOOLEANtrue—
    delete_thresholdoptFLOAT100.00.1–10000—
    delete_criteriaoptCOMBObboxarea2 options: bboxarea, circumference
    simplify_epsilonoptFLOAT1.00.1–20—
    merge_epsilonoptFLOAT5.00.1–20—
    buffer_distanceoptFLOAT5.00.1–20—
    operation_keyoptCOMBOhull2 options: hull, union

    Outputs (1)

    NameTypeDescription
    STRINGSTRING—