Nodes/PortraitUtils/Outpaint Padding Compute
ComfyUI Node

Outpaint Padding Compute

Turn '20% horizontal' into actual pixels, gravity-aware

By heyburns·Created 11 months ago·Updated 4 months ago· 1
Outpaint Padding Compute
  • image
  • left
  • top
  • right
  • bottom
modePercent
gravitycenter
horizontal_percent20.0
vertical_percent10.0
left_px0
right_px0
top_px0
bottom_px0

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 by vertical_percent/100, then distributes the padding according to gravity. Center splits it evenly both sides; bottom dumps the whole vertical budget on the bottom edge; corner gravities do the same for each axis. So gravity: 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_px literally, 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. center splits 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 IMAGE in; 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.

CategoryPortraitUtils/Config

Inputs (9)

NameTypeDefaultDescription
imageIMAGE
modeSTRINGPercent
gravitySTRINGcenter
horizontal_percentFLOAT20.00–10000
vertical_percentFLOAT10.00–10000
left_pxINT00–1000000
right_pxINT00–1000000
top_pxINT00–1000000
bottom_pxINT00–1000000

Outputs (4)

NameTypeDescription
leftINT
topINT
rightINT
bottomINT