Nodes/ComfyUI-Yuan/Image Resize (keep proportion)
ComfyUI Node

Image Resize (keep proportion)

Fit any image into a box without mangling the aspect ratio

By the-hexer·Created 2 years ago·Updated 10 months ago· 15
Image Resize (keep proportion)
  • image
  • image
  • Width
  • Height
â—„max_width1024â–º
â—„max_height1024â–º
â—„methodnearest-exactâ–º

The name says it all and that's refreshing: this node takes an image and two numbers, and resizes it to fit inside a box keeping the aspect ratio. No cropping, no distortion, no math on your part. ComfyUI's built-in ImageScale will happily stretch a 512×512 image into 1024×1024 and hand you a warped mess; this is the node you grab when "fit within, don't break the shape" is the actual requirement.

It's a small node from the tiny "ComfyUI-MoneyMaker" pack (repo is called ComfyUI-Yuan - Yuan is Chinese for money). It does one job and does it with the exact same upscaler ComfyUI's core uses, so there's little to be surprised by.

How it works

Under the hood it's dead simple. The source reads the image's (B, H, W, C) shape and checks whether it already fits inside max_width × max_height. If it does, it returns the image untouched. Otherwise it computes the scale factor as min(max_width / width, max_height / height) - the tighter of the two ratios - rounds the result, and runs it through comfy.utils.common_upscale with cropping disabled. Same engine as the stock resize nodes, so the output quality you're used to is what you get.

One honest gotcha buried in there: when the image already fits, the Width and Height outputs report the original dimensions, not your max_width/max_height. If you wire those into something expecting a fixed target size, you can get a silent surprise on images that don't need resizing.

The inputs that matter

  • image - an IMAGE tensor; a whole batch resizes together, so a video's worth of frames all scale as one.
  • max_width / max_height - your bounding box, both defaulting to 1024, range 1–8192. The image shrinks to fit; it never upscales past the box just to hit a size.
  • method - one of nearest-exact, bilinear, area, bicubic, lanczos, defaulting to nearest-exact. This is the one beginners trip on: nearest-exact is a poor choice for downscaling (jaggy aliasing). Use area when shrinking, and bicubic or lanczos when upscaling.

Outputs

image (the resized tensor), plus Width and Height as plain INTs. That pair is the real reason to install this - wire them into an Empty Latent Image, a latent resize, or a resolution node and you get dynamic resolution that always matches the resized frame. No extra "get image size" node needed.

Install

Same routine as any custom node - either ComfyUI Manager (search for ComfyUI-MoneyMaker or Yuan), or:

cd ComfyUI/custom_nodes
git clone https://github.com/Cyber-Blacat/ComfyUI-Yuan

then restart ComfyUI. No model downloads, no API keys, and the dependencies (torch, numpy, pillow, opencv-python, scikit-image) are all things a working ComfyUI install already has. It appears in the node menu under MoneyMaker😺/image.

Issues to expect

There isn't much to break here - it's one resize call. The real frustrations are the ones above: forgetting the Width/Height outputs lie about your max when no resize happened, and leaving the default nearest-exact while downscaling. Beyond that, know what you're getting into: this pack has essentially zero community footprint - you won't find a Reddit thread arguing about it - and the README doesn't even document this node. The code is short and readable if you ever want to confirm what it does. For a "shrink to fit and tell me the new size" job, it's a fine, dependency-free tool.

CategoryMoneyMaker😺/image

Inputs (4)

NameTypeDefaultDescription
imageIMAGE—
max_widthINT10241–8192—
max_heightINT10241–8192—
methodCOMBOnearest-exact5 options: nearest-exact, bilinear, area, bicubic, lanczos

Outputs (3)

NameTypeDescription
imageIMAGE—
WidthINT—
HeightINT—