Nodes/ComfyUI_Swwan/Image Pad (Swwan)
ComfyUI Node

Image Pad (Swwan)

Four ways to fill the gap, including the pillarbox blur

By aining2022·Created 10 months ago·Updated about 18 hours ago· 33
Image Pad (Swwan)
  • image
  • mask
  • images
  • masks
◄left0►
◄right0►
◄top0►
◄bottom0►
◄extra_padding0►
◄pad_mode▾►
◄color0, 0, 0►
◄target_width512►
◄target_height512►

Most pad nodes give you black bars and call it a day. This one gives you four different answers to "what goes in the empty space" - and one of them, pillarbox_blur, is the reason people seek it out.

It's the KJNodes pad lineage, re-registered under a Swwan ID, and it covers both the "add N pixels per side" and the "center me in this exact canvas" jobs in one node.

Inputs and outputs

Required: image (IMAGE), left, right, top, bottom (INT, default 0, 0–16384, step 1), extra_padding (INT, default 0), pad_mode (enum: edge, edge_pixel, color, pillarbox_blur), color (STRING, default 0, 0, 0; tooltip: "Color as RGB values in range 0-255, separated by commas").

Optional: mask (MASK), target_width and target_height (INT, default 512 each).

Outputs: images (IMAGE) and masks (MASK).

The four pad modes

edge fills each side with the mean of that edge - the average colour of the top row fills the top, and so on. Produces a smooth, smeared extension. Cheap, and surprisingly inoffensive on skies and gradients.

edge_pixel replicates the exact edge pixels all the way out, including addressing the corners with the corresponding corner pixel. Sharper and more literal than edge, and the one to use when you want a physically plausible continuation of a structured edge.

color is flat fill from the color string - comma-separated 0–255 RGB, parsed as ints. A single value is expanded to all three channels, so 128 gives you grey.

pillarbox_blur upscales the image to cover the whole canvas, desaturates it slightly, dims it to 35%, and blurs it, then pastes the original centered on top. That's the modern video-player look - a background that echoes the image without competing with it. It's the mode people come to this node for, and it's genuinely nice for making vertical content fit a horizontal frame.

Note that it's blur-and-dim, then paste - not a mirror or a stretch - so the subject appears twice in the frame, once sharp and once as a soft backdrop. For a thumbnail or a social crop that reads as intentional. For a technical prep step, it's not what you want.

Two ways to specify the padding

Per-side: set left/right/top/bottom, and extra_padding gets added to all four. So extra_padding=64 is "give me a 64-pixel border all the way around on top of whatever I set individually."

Target canvas: if you wire both target_width and target_height, those take over and the image is centered in that exact canvas - the per-side values and extra_padding semantics change, with extra_padding instead downscaling the image first to make room. Both of these are shown as inputs rather than free-standing widgets, so they're meant to be driven by a value node.

Unlike the outpaint pad nodes, the step here is 1, not 8. That's convenient for layout work and a footgun for VAE-related work: if the output is going to be encoded, round your padding yourself so the dimensions stay divisible by 8, or you'll get a fractional latent and a blurry or shifted reconstruction.

The masks output

Multi-purpose, and worth understanding before you wire it. With no mask input, masks is 1 everywhere and 0 over the original image region - "generate here," the same convention the outpaint nodes use. With a mask input, the mask is replicate-padded and returned, so it tracks your image through the pad. pillarbox_blur follows the same rule with a slightly different fill (a full 1-plane over the backdrop, with the original region carrying your mask or 0).

In other words: this node works as an outpaint prep too, just without the /8 alignment guarantees the dedicated outpaint nodes give you.

Install

cd /path/to/ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan.git
cd ComfyUI_Swwan
python -m pip install -r requirements.txt

Windows portable:

.\python_embeded\python.exe -m pip install .\ComfyUI\custom_nodes\ComfyUI_Swwan\requirements.txt

Restart ComfyUI, hard-refresh the browser, search Swwan; it's under Swwan/Advanced/Image. Requirements are the pack's usual vision extras over your existing torch - and note that the pillarbox blur is implemented as a hand-rolled separable Gaussian convolution rather than pulling in a filter library, so nothing else needs installing for it to work.

If a workflow that used the original KJNodes node now shows a missing node, that's the 1.0.0 namespace split talking, and the fix is the pack's migration tool: python scripts/migrate_workflow.py old.json --dry-run from the repo root.

CategorySwwan/Advanced/Image

Inputs (11)

NameTypeDefaultDescription
imageIMAGE—
leftINT00–16384—
rightINT00–16384—
topINT00–16384—
bottomINT00–16384—
extra_paddingINT00–16384—
pad_modeCOMBO4 options: edge, edge_pixel, color, pillarbox_blur
colorSTRING0, 0, 0Color as RGB values in range 0-255, separated by commas.
maskoptMASK—
target_widthoptINT5120–16384—
target_heightoptINT5120–16384—

Outputs (2)

NameTypeDescription
imagesIMAGE—
masksMASK—