Outpaint Padding Compute
Turn '20% horizontal' into actual pixels, gravity-aware
- image
- left
- top
- right
- bottom
Outpainting nodes need pixel numbers, but you think in percentages and directions. "Extend the scene down by 10%" is a human sentence; the padding node wants bottom: 217. OutpaintPaddingComputeNode is the translator: it takes an image plus the outpainting preferences (typically wired straight out of OutpaintConfigNode) and returns exact left, top, right, bottom pixel values - even-sized, corner-aware, ready to feed into your padding or outpaint node.
It accepts mode (Percent or Pixels), gravity (center / edges / corners), horizontal_percent and vertical_percent, and the four *_px values. How it computes depends on mode:
- Percent mode - multiplies the image's width by
horizontal_percent/100 and height byvertical_percent/100, then distributes the padding according togravity. Center splits it evenly both sides;bottomdumps the whole vertical budget on the bottom edge; corner gravities do the same for each axis. Sogravity: bottom+ 10% vertical on a 1080px-tall image gives you ~108px on the bottom and 0 on top. - Pixels mode - uses
left_px/right_px/top_px/bottom_pxliterally, and gravity is ignored (per the code's own comment: "Pixels mode: gravity ignored; enforce even final size").
In both modes it enforces an even final size - it rounds padding so the padded canvas has even dimensions, which matters because a lot of models and tiling pipelines quietly break on odd widths. The docstring spells out the corner case you'd otherwise discover at 2am: in Percent mode, corner gravities distribute both the horizontal and vertical budgets to the relevant edges.
The four integer outputs (left, top, right, bottom) are pure data - no image passes through, the image input is only used to read its dimensions for the percent math. Wire them into a padding node (like an image-pad or outpaint setup) and the whole branch inherits the config.
Install
Manager → search "PortraitUtils", or:
cd ComfyUI/custom_nodes
git clone https://github.com/heyburns/PortraitUtils
Restart. It only needs the image dimensions, so it's torch/numpy with no extra deps.
Common issues
- Padding is all on one side when you wanted even - that's
gravity, not a bug.centersplits evenly; any other gravity intentionally dumps the budget. - Values look too big/small - check
mode. In Percent mode the numbers scale with image size; in Pixels mode they're absolute. Mixing them up is the #1 surprise. - Odd dimensions downstream - the node enforces even output, but if you're feeding hand-typed px values from somewhere else they may be odd. Let this node own the numbers.
- It outputs nothing when the image is missing - the percent path needs the image's size. Wire a real
IMAGEin; it's not optional for Percent mode.
If you outpaint batches of photos, this is the node that keeps every frame's extension proportional - 10% down is 10% down whether the source is 800px or 4000px tall.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mode | STRING | Percent | — |
| gravity | STRING | center | — |
| horizontal_percent | FLOAT | 20.00–10000 | — |
| vertical_percent | FLOAT | 10.00–10000 | — |
| left_px | INT | 00–1000000 | — |
| right_px | INT | 00–1000000 | — |
| top_px | INT | 00–1000000 | — |
| bottom_px | INT | 00–1000000 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| left | INT | — |
| top | INT | — |
| right | INT | — |
| bottom | INT | — |