Nodes/comfyui-panels/String Decode Panel Layout
ComfyUI Node

String Decode Panel Layout

Turn a Line of Layout Text Back Into a Comic Page

By bmad4ever·Created 12 months ago·Updated 2 months ago· 41
String Decode Panel Layout
    • PANEL_LAYOUT
    layout_codePaste the layout code here.

    A panel layout in the comfyui_panels pack is an abstract tree of cuts - not a list of rectangles. This node rebuilds that tree from a compact text string, which is handy in a way that only clicks once you've tried keeping layouts as PNGs. bmad_StringDecodePanelLayout is the "load from text" half of the pack's encode/decode pair: String Encode Panel Layout serializes a layout, this node deserializes it.

    Why text beats images here

    The pack's normal save/load path embeds the layout in a PNG's metadata (Load Panel Layout / Save Panel Layout). That works, but it means your layout is glued to an image file. Encode-to-text gives you a layout you can paste into a notes file, a prompt, a Discord message, a git repo, or a comment in your workflow JSON. Decode brings it back with zero file juggling. If you've got a page structure you reuse constantly, freezing it as a string and pasting it into a Text node is genuinely nicer than keeping a folder of layout PNGs around.

    How it works

    The string is a compact serialization of the cut tree. A real one from the pack's sample layouts looks like:

    H-4_2(V-5_0(H17_1(,),),)
    

    Each node in the tree is a cut: V or H for vertical/horizontal, the number after that is the angle in degrees (negative = slanted the other way), the number after the underscore is the split mode (how the cut position is chosen - midpoint, thirds, golden ratio, and so on), and the parentheses hold child cuts, comma-separated. An empty slot means "no further cuts here." The parser, CutNode.from_compact, handles the nesting.

    The one input and what it does

    Just layout_code, a STRING - paste your code in. Its default value is literally "Paste the layout code here." which is the author's way of saying this node does nothing useful until you give it real data. Feed it garbage and you'll get a parse error, not a graceful empty layout.

    The single output is a PANEL_LAYOUT object, which wires straight into Build Layout Panels (paired with a canvas polygon from Canvas Panel) to turn the tree back into actual shapely.Polygon panels, and from there into masks, crops, and the rest of your page-assembly chain.

    The trap

    The code is compact on purpose, so don't try to hand-edit it much - it's fine to tweak an angle here or a split mode there once you know the format, but for real edits, mutate the layout with the pack's Mutate Panel Layout node and re-encode. Also, decode is strict: the string encodes the abstract cut tree, not concrete panel properties like corner rounding or line thickness. Those live downstream, applied by other nodes after the layout becomes panels.

    Install

    Part of bmad4ever/comfyui_panels. Via ComfyUI Manager, search comfyui-panels and install, or:

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

    Restart ComfyUI and it'll be under Bmad/Panels. No models to download - the pack's dependencies are shapely, matplotlib, and opencv-python.

    CategoryBmad/Panels

    Inputs (1)

    NameTypeDefaultDescription
    layout_codeSTRINGPaste the layout code here.

    Outputs (1)

    NameTypeDescription
    PANEL_LAYOUTPANEL_LAYOUT