Nodes/ComfyUI_toyxyz_test_nodes/ImageResize_Padding
ComfyUI Node

ImageResize_Padding

Letterbox anything to a fixed canvas without stretching it

By toyxyz·Created 3 years ago·Updated a day ago· 635
ImageResize_Padding
  • image
  • IMAGE
  • width
  • height
width512
height512
interpolation
paddingtrue
Red0.0
Green0.0
Blue0.0

Every batch workflow eventually hits the boring problem this node solves: images need to be the same size, and just stretching them looks wrong. ImageResize_Padding resizes an image to an exact width × height while keeping its proportions, then fills the leftover margins with whatever solid color you pick. That's it - letterboxing, done properly, with the padding color under your control.

Why bother? Because a ton of ComfyUI pipelines demand exact dimensions downstream. img2img where your reference has to match the latent size, ControlNet conditions that need to line up with the sampler's resolution, compositing multiple results into a fixed grid - all of them break or look soft if sources arrive at mismatched sizes. If you're doing regional prompting or feeding a fixed-canvas model like SDXL's 1024-ish multiples, this gets everything onto one canvas without squashing anyone's face.

How it works

The mechanism is straightforward and worth understanding because it explains one of the node's quirks. With padding on, it computes the source's aspect ratio, works out how much padx/pady is needed to hit the target aspect ratio, pads with your fill color, and then resizes to exactly your width × height.

Here's the quirk: it always resizes with comfy.utils.lanczos. The interpolation dropdown is there in the inputs, but the current source never reads it - every path lands on Lanczos. It's a cosmetic setting in this version, so don't hunt for quality differences between nearest and bicubic; you won't find them. That's not a bad thing, honestly. For "make these pixels bigger without inventing detail," Lanczos is exactly the right tool - it's the non-generative upscaler the community reaches for when the source is already sharp (the kind of thing you'd otherwise use an ESRGAN model for, which is overkill here).

Inputs and outputs

The ones you'll actually set:

  • width / height - target size, defaults 512, up to 16384.
  • padding - on (default) letterboxes; off means a straight stretch-resize that ignores aspect ratio.
  • Red / Green / Blue - the fill color as 0–1 floats, default black. Set all three to 1 for white bars.
  • interpolation - cosmetic in the current code, as noted above.

The node returns three outputs: the resized IMAGE, plus width and height as integers. Those ints are handy when a downstream node wants to know the canvas size without you hardcoding it.

Installing and pitfalls

It ships in toyxyz/ComfyUI_toyxyz_test_nodes, so install the whole pack via ComfyUI Manager (search the pack title) or:

cd ComfyUI/custom_nodes
git clone https://github.com/toyxyz/ComfyUI_toyxyz_test_nodes

then restart ComfyUI. Honest trade-off: this is a utility you might want for one workflow, and installing the pack drags in its heavier deps (OpenCV, pywin32, trimesh and friends) for the sake of one resize node. If you're already running the pack for the webcam loop it's free; if you're not, weigh it.

One real gotcha: keep both width and height above zero. The aspect-ratio math divides by the target dimensions, so a 0 in either will throw a divide-by-zero error rather than gracefully auto-sizing.

CategoryToyxyzTestNodes

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
widthINT5120–16384
heightINT5120–16384
interpolationCOMBO6 options: nearest, bilinear, bicubic, area, nearest-exact, lanczos
paddingBOOLEANtrue
RedFLOAT0.00–1
GreenFLOAT0.00–1
BlueFLOAT0.00–1

Outputs (3)

NameTypeDescription
IMAGEIMAGE
widthINT
heightINT