Nodes/ComfyUI-Hangover-Nodes/Image Scale Bounding Box
ComfyUI Node

Image Scale Bounding Box

Resize into a fixed box without stretching anything

By Hangover3832·Created 3 years ago·Updated about a year ago· 41
Image Scale Bounding Box
  • image
  • IMAGE
upscale_method
box_width512
box_height512
padding
pad_color0

The problem with a plain resize node is it doesn't care about aspect ratio - tell it 1024x1024 and a 16:9 photo comes out squished. This node solves the boring-but-annoying version of that problem: fit an image into a box of a given width and height, keep its proportions intact, and - if you actually need the output to be exactly that box size, not just "small enough to fit inside it" - pad the leftover space with a color of your choice. It's the kind of node you don't think about until a downstream step demands a fixed resolution and your images are all slightly different shapes.

What it is and why you'd use it

Think of it as "fit inside a box" rather than "force into a box." Feed it a portrait image and a 512x512 box, and instead of squashing it into a square, it scales the image down until its longer side hits 512, leaving the shorter side under 512. If you leave padding off, that's it - you get a correctly-proportioned image that's no bigger than your box in either dimension, but not necessarily exactly box-sized. If you turn padding on, it fills the remaining space so the output is exactly box_width x box_height, which matters when something downstream - a batch grid, a fixed-size model input, a canvas composite - needs every image to be the identical pixel size.

It's a genuinely common building block: dataset prep for training (normalize a folder of oddly-sized images to one canvas size without distortion), pre-processing before feeding a model with a fixed expected resolution, or just making a contact sheet where every tile needs to be the same size. As of a recent update it also runs on batches, so you're not stuck looping it over single images one at a time.

The inputs and outputs that matter

  • image - your input image (or batch).
  • upscale_method - the resampling algorithm: lanczos, nearest-exact, bilinear, area, or bicubic. Lanczos is the safe default for photographic content - sharp without ringing artifacts. Reach for nearest-exact only if you specifically want blocky, non-interpolated pixels (pixel art, masks).
  • box_width / box_height (default 512 each, up to 16384) - the target box dimensions.
  • padding - none, center, top, left, right, or bottom. none just scales to fit inside the box with no guarantee of hitting the exact size. Any of the others pads the shorter dimension out to the full box, anchoring the actual image at that edge (or centered).
  • pad_color - an integer from 0 to 16777215. That range is a packed 24-bit RGB value, not a special unit of its own: 0 is black, 16777215 (0xFFFFFF) is white, and anything in between is a standard RGB triple squashed into one number. If you want a specific color, convert its hex code to decimal first.

Output is a single IMAGE, ready to wire into whatever needed the fixed size in the first place - a save node, a batch composite, a model that expects a particular input resolution.

Installing it

Search ComfyUI-Hangover-Nodes in ComfyUI Manager, or clone it by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/Hangover3832/ComfyUI-Hangover-Nodes

Restart ComfyUI. This one has no model downloads and no special dependencies - it's plain image math (resize plus a paste), so once the pack is installed it just works.

Common issues and things to know

The one mix-up people hit: leaving padding on none and then being confused the output isn't exactly box_width x box_height. That's expected - none only guarantees the image fits inside the box, not that it fills it. If your downstream node needs an exact size, you need padding enabled.

The other thing worth knowing before you reach for pad_color: since it's a raw packed-RGB integer rather than a color picker, it's easy to type a value you didn't mean (typing "255" thinking "pure color" gives you a very dark, almost-black blue, not what most people expect). If you're not sure of the number, work it out from a hex code rather than guessing.

Beyond that, there's not much to trip over - it's a small, self-contained utility node, and the pack overall (while marked by its author as no longer actively maintained) is stable enough that a plain resize-and-pad operation isn't likely to break on you.

CategoryHangover

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
upscale_methodCOMBO5 options: lanczos, nearest-exact, bilinear, area, bicubic
box_widthINT5121–16384
box_heightINT5121–16384
paddingCOMBO6 options: none, center, top, left, right, bottom
pad_colorINT00–16777215

Outputs (1)

NameTypeDescription
IMAGEIMAGE