Nodes/ComfyUI_SVG-Suite/SVG Optimize (Scour)
ComfyUI Node

SVG Optimize (Scour)

Full Scour control when the presets aren't enough

By MushroomFleet·Created about a year ago·Updated 5 months ago· 9
SVG Optimize (Scour)
    • STRING
    ◄svg_string—►
    â—„enable_viewboxingtrueâ–º
    â—„enable_id_strippingtrueâ–º
    â—„enable_comment_strippingtrueâ–º
    â—„shorten_idstrueâ–º
    â—„indent_typenoneâ–º
    â—„strip_xml_prologtrueâ–º
    â—„strip_xml_space_attributetrueâ–º
    â—„remove_metadatatrueâ–º
    â—„remove_descriptive_elementstrueâ–º
    â—„strip_ids_prefixâ–º
    â—„simplify_colorstrueâ–º
    â—„precision5â–º
    â—„newlinesfalseâ–º
    â—„sort_attrsfalseâ–º
    â—„group_createfalseâ–º
    â—„protect_ids_prefixâ–º

    Scour is the long-running Python library for shrinking SVGs, and SVG Optimize (Scour) is a thin, honest wrapper around it - every toggle maps to a real Scour option. If SVG Optimize Presets is the "just do it" button, this is the instrument panel. You reach for it when you need to control exactly what gets stripped, or when a preset did something you didn't want and you need to bisect why.

    The toggles that matter

    The five required ones are the daily drivers:

    • enable_viewboxing - adds/keeps a viewBox for proper scaling.
    • enable_id_stripping and shorten_ids - the two-edged swords. IDs are markup bloat, but if your workflow selects elements by ID, stripping them destroys your handles. Defaults are true, and that's the thing most people trip on.
    • enable_comment_stripping - removes comments.
    • indent_type - none / space / tab. For output destined to be re-edited, space or tab keeps it readable.

    The optional section is where the real power (and danger) lives: remove_metadata, remove_descriptive_elements (titles/descriptions), strip_xml_prolog, simplify_colors (converts colors to shorter forms), precision (0–10 decimal places for coordinates - the file-size lever), newlines, sort_attrs, group_create, plus strip_ids_prefix / protect_ids_prefix to surgically strip or protect IDs that start with a given string. protect_ids_prefix is the one that rescues you when you have IDs you need and don't want shorten_ids to mangle.

    How it works

    It builds a Scour sanitizeOptions() object from your inputs and runs scourString(). Output is a single STRING: the optimized SVG. Because it's literally Scour, everything you already know about Scour applies - including the caveat that aggressive optimization can change rendering (collapsing groups, rewriting colors, renumbering or stripping IDs).

    Install

    Pack standard:

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

    Restart ComfyUI, or via Manager under "svg-suite". Requires Scour; if it's missing, the node prints an error and silently returns your original SVG - the pack's favorite failure mode.

    Where people get burned

    The README's own recommended pipeline puts optimization last, after compression and editing. Respect that order: optimizing early strips the very IDs and structure you'll want for downstream editing.

    And start conservative. The defaults here are more aggressive than the "default" preset (id stripping and comment stripping are on), so this node will visibly change your file even at defaults. If you just want a light pass, drop to SVG Optimize Presets. If you want control, this is the tool - just be deliberate: strip IDs only if nothing references them, and set protect_ids_prefix for the ones that do.

    Category💎TOSVG/Advanced

    Inputs (17)

    NameTypeDefaultDescription
    svg_stringSTRING—
    enable_viewboxingBOOLEANtrue—
    enable_id_strippingBOOLEANtrue—
    enable_comment_strippingBOOLEANtrue—
    shorten_idsBOOLEANtrue—
    indent_typeCOMBOnone3 options: none, space, tab
    strip_xml_prologoptBOOLEANtrue—
    strip_xml_space_attributeoptBOOLEANtrue—
    remove_metadataoptBOOLEANtrue—
    remove_descriptive_elementsoptBOOLEANtrue—
    strip_ids_prefixoptSTRING—
    simplify_colorsoptBOOLEANtrue—
    precisionoptINT50–10—
    newlinesoptBOOLEANfalse—
    sort_attrsoptBOOLEANfalse—
    group_createoptBOOLEANfalse—
    protect_ids_prefixoptSTRING—

    Outputs (1)

    NameTypeDescription
    STRINGSTRING—