Nodes/ComfyUI/Resize And Pad Image
ComfyUI Node Runs on cloud

Resize And Pad Image

Shove any image into a box without wrecking its shape

By Comfy-Org·Created 4 years ago·Updated about 16 hours ago· 130,493
Resize And Pad Image
  • image
  • IMAGE
target_width512
target_height512
padding_color
interpolation

This is the "fit to size" node - its own search alias says so. You tell it a target canvas, it shrinks or grows your image to fit inside that box while keeping the aspect ratio intact, then centers it and fills the leftover space with a solid color. No stretching, no cropping, no missing subject. If you've ever fought with a model or a workflow that demands a fixed resolution and cursed your odd-shaped input, this is the polite way to comply.

It's a newer built-in, part of the current generation of ComfyUI core nodes - ships with the base install, nothing to add.

How it works

The math is the point: it computes scale = min(target_width / width, target_height / height) and uses the smaller one. That's the "contain" fit - the image always fully fits, and the smaller axis gets the padding. A 2000×1000 image into a 512×512 box scales down to 512×256, centered vertically, with 128px of padding above and below. The image never distorts.

Then two choices shape the result:

  • padding_color - white or black. That's it, no custom hex in the core node. Black for dark scenes and masks, white for documents and bright work.
  • interpolation - area, bicubic, nearest-exact, bilinear, or lanczos. Same rules as everywhere else in ComfyUI: area for downscaling, lanczos for upscaling, nearest-exact if you're resizing pixel art and want it to stay crunchy.

Inputs are image, target_width, target_height (both 1–16384, default 512), and those two combos. Output is a single IMAGE at exactly target_width×target_height.

Why you'd actually use it

Three real jobs:

  1. Normalizing a mixed batch. Images from different sources, different aspect ratios, all need to be the same dimensions before they hit a batch operation or a model that wants a fixed canvas.
  2. Prepping reference images for a workflow that expects a specific resolution - feeding a ControlNet or a VLM that was fine-tuned on square inputs.
  3. Training-data prep where your dataloader wants uniform sizes and you'd rather letterbox than crop away content.

It's a small, honest utility. That's the whole appeal: one node, a "contain" fit, no surprises.

Where it bites

The padding is the gotcha. That white or black band becomes real image data - a model sampling the padded canvas will happily extend the image into the padding or hallucinate a border around it, and the letterbox is visible if you decode straight to an image. This node is for preprocessing, not for the last step before sampling. If your model needs specific content in the padding (the outpaint trick of "pad with red, tell the model to remove it"), this node's white/black palette won't do - reach for ImagePadForOutpaint, which fills with neutral gray and gives you the mask.

Second: "contain" means your content gets smaller than the original. A 4K photo fitted into 512×512 is a 512-wide image with letterbox bars. If you want to keep maximum resolution, center-crop instead, or resize without a fixed box. And since the padding color is fixed, don't use it to build transparency - there's no alpha handling here.

Small node, small mistakes. Set your target to a latent-friendly multiple of 8, pick area for downscaling, and remember the bars are part of the output.

Categoryimage/transform

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
target_widthINT5121–16384
target_heightINT5121–16384
padding_colorCOMBO2 options: white, black
interpolationCOMBO5 options: area, bicubic, nearest-exact, bilinear, lanczos

Outputs (1)

NameTypeDescription
IMAGEIMAGE