Nodes/ComfyUI-HM-Tools/Normalize Image With Rectangle
ComfyUI Node

Normalize Image With Rectangle

Every image, one fixed canvas, no stretching

By hiderminer·Created about a year ago·Updated about a year ago· 0
Normalize Image With Rectangle
  • image
  • IMAGE
width512
height512

Sometimes you need everything in a batch to be exactly 512×512 - a contact sheet, a fixed-size model input, a uniform canvas to composite onto - but you don't want your images stretched like taffy. Normalize Image With Rectangle is the "fit inside a box, letterbox the rest" node for that job. It resizes each image to fit within the width and height you give it while keeping the aspect ratio, then pads the leftover space with transparent bars, centered. Out comes an IMAGE that's always exactly the dimensions you asked for.

It's the mirror image of the pack's other node, Auto Crop Image - that one trims transparent dead space, this one adds it back on a fixed canvas. Use them together: crop the padding off a cutout, then normalize it onto whatever canvas your pipeline expects.

How it works

Given a target width and height, the node works out the scaling factor as the smaller of width / img_w and height / img_h, resizes with bilinear interpolation, then centers the result on a canvas of exactly the target size. The mechanics matter here:

  • RGB input becomes RGBA. The image area gets alpha 1, the padding bars get alpha 0, so the letterboxing is genuinely transparent, not black.
  • RGBA input keeps its alpha, and the bars are still set to transparent.

Because resizing happens before padding, the bars are always clean - nothing bleeds from the image into them.

One real gotcha, though, and it comes straight from the code: if your input is already RGBA, the bilinear resize runs across all four channels including alpha. That's the classic recipe for a semi-transparent halo around the subject's edges after a resize. RGB inputs dodge this because alpha is only added after the resize. So if you're normalizing cutouts with transparency, feed them in as RGB when you can, or accept some edge fringing.

The inputs that matter

You only really touch three things:

  • image - your IMAGE tensor, batch-friendly.
  • width - target width, 1–8192, default 512.
  • height - target height, 1–8192, default 512.

That's the whole surface. Set the two ints, connect the output into whatever accepts IMAGE (Preview, Save, a VAE encode, a compositor), and you're done. The output always matches the target dimensions exactly - that's the entire contract of the node.

Worth knowing before you build a workflow on it

The README itself labels this node "under development and testing" - behavior may change between versions. It's from a small personal utility pack (hiderminer's ComfyUI-HM-Tools, © 2025, GPL-3.0), so don't treat it as battle-tested core. There's also no round-trip guarantee: pad first and crop later and you'll land where you started, but the two operations aren't perfectly inverse on arbitrary inputs.

Install

Same story as the pack's other node: ComfyUI Manager → search "HM-Tools" → install → restart, or clone manually:

cd ComfyUI/custom_nodes
git clone https://github.com/hiderminer/ComfyUI-HM-Utilities
# restart ComfyUI

No requirements.txt, no model files, no heavy deps - just torch and numpy, both already in your ComfyUI environment. About the only way to break it is feeding it a width or height below 1 or above 8192, and the UI clamps those anyway. For a utility this thin, that's a refreshing amount of "it just works."

Categoryimage/processing

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
widthINT5121–8192
heightINT5121–8192

Outputs (1)

NameTypeDescription
IMAGEIMAGE