ComfyUI Node

Compute Padding

A tiny math node that tells you how much padding to add — and nothing else

By Isi-dev·Created 2 years ago·Updated 10 months ago· 33
Compute Padding
    • left
    • right
    • top
    • bottom
    width512
    height512
    targetWidth768
    targetHeight768
    leftPadding0
    topPadding0
    centralizeHorizontaltrue
    centralizeVerticalfalse

    Let's set expectations right away: this node does not pad anything. It computes the four padding amounts - left, right, top, bottom - you'd need to stretch one image size up to a target canvas, and hands them to you as integers. That's the entire job. If you were hoping for a padded image, you want ComfyUI's built-in padding node; this one is the calculator that feeds it.

    So why does it exist? This pack's compositing nodes (Move In_Or_Out, Replace Img_or_Vid_Bg, and friends) all care about exact canvas sizes, and the pack is built around dynamic, size-flexible workflows where images arrive at whatever resolution. When you're wiring sizes around the graph, sometimes you want the numbers, not the padded image - to plug into an offset, a pad node, or another node that needs explicit dimensions. That's this node's lane.

    The math is plain arithmetic, easy to read in the source: if centering is on, padding is split evenly between both sides (left = right, or top = bottom). If not, the leftPadding / topPadding values you supply are used as the fixed side, and the opposite side absorbs whatever's left to hit the target - with overflow handled by borrowing back from the fixed side and everything clamped at zero. Feed it a source bigger than the target and you get all zeros.

    Inputs that matter

    • width / height - your source image size (defaults 512×512).
    • targetWidth / targetHeight - the canvas you want to reach (defaults 768×768).
    • centralizeHorizontal - on by default. Splits horizontal padding evenly.
    • centralizeVertical - off by default. This asymmetric pair is the one gotcha: out of the box you get a canvas centered horizontally but pinned to the top vertically. Flip centralizeVertical on if you want it centered both ways.
    • leftPadding / topPadding - only consulted when centering is off for that axis.

    Outputs are four INTs: left, right, top, bottom. Feed them into whatever consumes padding amounts.

    Installing it

    Part of the ComfyUI-Animation_Nodes_and_Workflows pack from Isi-dev. Install once, get all the nodes:

    • ComfyUI Manager → search ComfyUI-Animation_Nodes_and_Workflows → install, restart.
    • Or manually:
    cd ComfyUI/custom_nodes
    git clone https://github.com/Isi-dev/ComfyUI-Animation_Nodes_and_Workflows
    cd ComfyUI-Animation_Nodes_and_Workflows
    pip install -r requirements.txt
    

    Note the pack's requirements list mediapipe, which is genuinely heavy - but it's only needed for the pack's LivePortrait face node. This one is pure Python integer math; it runs on a toaster. No models, no downloads.

    Honestly, this is the node you reach for when you're building a workflow where sizes come from elsewhere - an image loader, a latent size node - and you don't want to hardcode padding. If you're just padding one static image, skip it and use the core pad node. But if your canvas is dynamic, it's the difference between manual numbers and numbers that recompute themselves. Small, unglamorous, does one thing.

    CategoryIsi-dev Animation nodes

    Inputs (8)

    NameTypeDefaultDescription
    widthINT51232–18446744073709550000
    heightINT51232–18446744073709550000
    targetWidthINT76832–18446744073709550000
    targetHeightINT76832–18446744073709550000
    leftPaddingINT00–18446744073709550000
    topPaddingINT00–18446744073709550000
    centralizeHorizontalBOOLEANtrue
    centralizeVerticalBOOLEANfalse

    Outputs (4)

    NameTypeDescription
    leftINT
    rightINT
    topINT
    bottomINT