ComfyUI Node

Simple Padding

When a bounding box is too tight, this node grows it

By alexlawford·Created 2 years ago·Updated 2 years ago· 0
Simple Padding
    • x
    • y
    • width
    • height
    x0
    y0
    width0
    height0
    padding0

    Detectors lie. Well, not lie - they're just stingy. A GroundingDINO or face-detector box hugs its subject so tightly there's no room for the model to see context, which is exactly why the detailing playbook says "grounding boxes are tighter than you expect, so pad them." Simple Padding is the node that does that padding, for the case where your box is just four numbers: x, y, width, height.

    It's the most basic kind of ComfyUI custom node there is: pure math, five integer inputs in, four integer outputs out. No models, no API, no files to download. You hand it a box and a pad amount, it hands you a bigger box. That's the whole job.

    How it works (read the source, not the README)

    The README calls padding simply "the number to pad by," which sounds symmetric. The actual code is more specific:

    x1b = X1 - padding if X1 - padding > 0 else 0
    y1b = Y1 - padding if Y1 - padding > 0 else 0
    width = width + padding
    height = height + padding
    

    Work through that and here's the gotcha: the right and bottom edges don't move. x and y get pulled toward the top-left by padding, and width/height grow by padding - so the box extends only up and to the left. If your box sits at (100, 100) with size 200×200 and you pad by 50, you get (50, 50) at 250×250. The center shifted; the far edges stayed put. That's almost never the direction you actually want, and since the padding is clamped at zero for x/y, a box parked at the canvas corner just stops growing. If you need padding that expands on all sides around the box's center, do the arithmetic in ComfyUI's core Math Expression node instead - that's the honest comparison here, because for plain symmetric padding this node is the wrong tool.

    Two more quirks while we're here. It has no idea what an image is - feed it numbers, it returns numbers, and it can't clamp to canvas bounds on the right or bottom. And the README's input list has width and height described as each other (it calls width "the height of the box"), which is pure label scramble and doesn't affect anything, since both are just plain integers.

    The inputs that matter

    All five are INT, all default to 0:

    • x, y - top-left corner of your unpadded box
    • width, height - box dimensions (not pixels of a canvas, just numbers)
    • padding - how much to grow up-left (see above)

    It returns x, y, width, height as four INT sockets - exactly the shape you feed a crop node or a PrimitiveBoundingBox's inputs. Wire a detector's box values in, crank padding to a few dozen pixels, and hand the result to your crop/detailer for context the model can actually use.

    Installing it

    No dependencies, no models, nothing heavy - requirements.txt is empty and pyproject.toml lists zero deps. Either clone it in:

    cd ComfyUI/custom_nodes
    git clone https://github.com/alexlawford/comfyui-simple-padding
    

    …then restart ComfyUI, or install it from ComfyUI Manager by searching "comfyui-simple-padding."

    Where people get tripped up

    The one genuinely annoying thing: the pack's category is literally CustomNodesTemplate, and there's leftover template scaffolding in the source (a CalculatorModel that does nothing, phantom my-custom-nodes paths). This is clearly the author's starter-project-style node, not a maintained tool - so don't hunt for it under "utils." Open the node menu and search "Simple Padding," and remember the up-left-only behavior. It won't error, it won't break your graph; it'll just quietly expand the box in the wrong direction until you notice the crop is off-center.

    CategoryCustomNodesTemplate

    Inputs (5)

    NameTypeDefaultDescription
    xINT0
    yINT0
    widthINT0
    heightINT0
    paddingINT0

    Outputs (4)

    NameTypeDescription
    xINT
    yINT
    widthINT
    heightINT