Nodes/comfy_Pond_Nodes/🐳图像背景填充V2
ComfyUI Node

🐳图像背景填充V2

How to force any image into an exact frame without destroying it

By Pondowner857·Created about a year ago·Updated 21 days ago· 45
🐳图像背景填充V2
  • image
  • image
target_width512
target_height512
resize_mode
padding_color
position
custom_color#FFFFFF

Sooner or later every ComfyUI workflow needs "make this image exactly 1024×1024 without stretching it into a mess." That's this node. 🐳图像背景填充V2 (Image Resize And Pad Fixed) is the Pond Nodes answer to letterboxing: it resizes your image to fit inside a canvas you specify, then fills whatever space is left with a color. One input image in, one perfectly-sized image out.

The reason you want this instead of a bare resize node is that it doesn't just squash pixels. "Fit" a portrait into a square canvas and you get a clean square with the photo centered and bars on the sides - which is exactly what img2img, ControlNet, and most samplers are happier receiving, because they don't have to deal with a weird non-standard aspect ratio.

How it works

The resize_mode dropdown is the whole game, and it's worth understanding the four options because they behave very differently:

  • fit - scale to fit inside the target, preserving aspect ratio, then pad the leftover space. This is letterboxing, the default mental model.
  • fill - scale to cover the whole target, then center-crop the overflow. Nothing is left empty, but you lose the edges of the image.
  • stretch - resize to exactly the target dimensions, distorting the aspect ratio. Almost never what you want; keep it for when you genuinely don't care.
  • none - don't scale at all. If the image is bigger than the canvas it gets center-cropped; if it's smaller it just sits there with padding around it.

Once the image is sized, padding_color paints the leftover area (white, black, gray, red, green, blue, or custom), and position drops the image into one of nine anchor spots - center, any corner, any edge. On a square canvas, top-left + black padding is the classic "comic panel" look; center is what you want 95% of the time.

The custom_color input is a hex string like #FF5733 that activates when you pick "custom" as the padding color.

The inputs and output

  • image - anything that outputs an IMAGE.
  • target_width, target_height - 1 to 8192, defaults 512. These are the exact dimensions of the output canvas.
  • resize_mode, padding_color, position, and optional custom_color as above.

The single image output is the padded result. It's sized exactly to your target, so it'll feed a latent resize, an upscaler, or a Save Image without surprises.

This is the "V2" of the pair: it takes fixed numbers. If instead you want to match the size of another image automatically - say, a reference frame or a mask's canvas - the pack's ImageResizeAndPadWithReference sibling does that, and even hands you the resulting width and height as integers.

Install

Pond Nodes is one repo, one install:

ComfyUI Manager → search "Pond Nodes" (comfy_Pond_Nodes)

or:

cd ComfyUI/custom_nodes
git clone https://github.com/Pondowner857/comfy_Pond_Nodes
cd comfy_Pond_Nodes
pip install -r requirements.txt

Restart ComfyUI after. This node only uses Pillow and numpy, so you can ignore most of what's in that requirements.txt. No models to download. One thing to keep in the back of your mind: the pack's README flags a console-spam conflict with comfyui_HiDream-Sampler - if your logs suddenly flood, that's the interaction, not this resize node.

Category🐳Pond/image

Inputs (7)

NameTypeDefaultDescription
imageIMAGE
target_widthINT5121–8192
target_heightINT5121–8192
resize_modeCOMBO4 options: fit, fill, stretch, none
padding_colorCOMBO7 options: white, black, gray, red, green, blue, +1
positionCOMBO9 options: center, top-left, top-center, top-right, middle-left, middle-right, +3
custom_coloroptSTRING#FFFFFF

Outputs (1)

NameTypeDescription
imageIMAGE