Nodes/Image Misc/Pad Image (KJ/SET)
ComfyUI Node

Pad Image (KJ/SET)

Add borders that are a color, an edge, or a blurred version of the image

By set-soft·Created about a year ago·Updated 8 months ago· 2
Pad Image (KJ/SET)
  • image
  • mask
  • images
  • masks
left0
right0
top0
bottom0
extra_padding0
pad_mode
color#000000
target_width512
target_height512
pad_transparency1.0

Padding is one of those operations you think you'll never need until suddenly every workflow you load wants it - to reach a VAE-friendly size, to add outpainting room, to letterbox an image into a canvas. This node is a port of Kijai's KJNodes ImagePad with a few things added, and it's the cleanest way to grow a canvas in ComfyUI.

The core inputs are exactly what you'd guess: left, right, top, bottom in pixels, and an extra_padding applied to all sides. Then it gets interesting - there are four pad_mode options for what fills the empty space, and a target_width/target_height shortcut that bypasses per-side math entirely.

The modes and the shortcut

  • color - fill with the color you specify (hex #RRGGBB, or comma-separated RGB in 0–255 or 0.0–1.0). The default and the simplest.
  • edge - fill each side with the average color of the nearest image edge. Good for a seamless-ish blend when the subject is solid color.
  • edge_pixel - repeat the outermost row/column of actual pixels. Keeps gradients alive across the join.
  • pillarbox_blur - the showy one: fills the border with a scaled-up, blurred, desaturated, and dimmed copy of the image itself. Great for previews and social thumbnails where you want context, not black bars.

The shortcut: connect both target_width and target_height, and the node centers the image inside that exact canvas - no mental arithmetic for left vs right. Set one of them to 0 and that dimension keeps the image's own size. Also worth knowing: extra_padding in target mode actually shrinks the source image first (with a high-quality lanczos downscale) so the total lands on the target - a handy trick for fitting into exact dimensions.

The optional mask gets padded in lockstep with the image, and pad_transparency controls the mask value in the padded area - 1.0 fully transparent, 0.0 fully opaque. That's a SET addition over KJNodes, and it's what makes padded-out masks play nicely with compositing instead of dumping a hard black border into your alpha.

Outputs

images (the padded image) and masks (the padded mask). Note the mask convention: 1 = transparent, 0 = opaque, which is the reverse of RGBA alpha.

Installing it

Part of Image Misc:

cd ComfyUI/custom_nodes
git clone https://github.com/set-soft/ComfyUI-ImageMisc
cd ComfyUI-ImageMisc && pip install -r requirements.txt

or ComfyUI Manager → "Image Misc", then restart. Under image/manipulation.

Where people get caught

The target_width/target_height inputs only kick in when both are connected - leave one dangling and the per-side values rule. And if your image has an alpha channel (RGBA), the color pad transparently fills rather than painting over; that's intentional, but it surprises people who expected opaque black. For a one-stop resize-plus-pad that handles aspect ratios too, the sibling Resize Image (KJ/SET) node wraps this one and is usually the better starting point - this node is the raw building block underneath.

Categoryimage/manipulation

Inputs (12)

NameTypeDefaultDescription
imageIMAGE
leftINT00–16384
rightINT00–16384
topINT00–16384
bottomINT00–16384
extra_paddingINT00–16384
pad_modeCOMBO4 options: edge, edge_pixel, color, pillarbox_blur
colorSTRING#000000Color for fill. Can be an hexadecimal (#RRGGBB). Can comma separated RGB values in [0-255] or [0-1.0] range.
maskoptMASK
target_widthoptINT5120–16384Connect both `target` inputs If 0 the size of the image is used Overrides left/right/top/bottom
target_heightoptINT5120–16384Connect both `target` inputs If 0 the size of the image is used Overrides left/right/top/bottom
pad_transparencyoptFLOAT1.00–1The transparency for the padded area for all modes except `edge_pixel`.1.0 is fully transparent, 0.0 is fully opaque.

Outputs (2)

NameTypeDescription
imagesIMAGE
masksMASK