Nodes/Various ComfyUI Nodes by Type/Image Resize by Longer Side
ComfyUI Node

Image Resize by Longer Side

Scale to a max dimension, keep the aspect ratio

By jamesWalker55·Created 3 years ago·Updated about a year ago· 215
Image Resize by Longer Side
  • image
  • IMAGE
size512
interpolation_mode

This is the resize node you want when you care about a maximum size but refuse to distort the image. JWImageResizeByLongerSide scales the image so its longer edge equals the size you give, and the shorter edge follows to keep the aspect ratio. Set size to 1024 and a 1600×900 photo becomes 1024×576; a 900×1600 portrait becomes 576×1024. Same longer edge, no stretching, orientation-agnostic.

That "whichever side is longer" behaviour is exactly what you want for fitting arbitrary user images into a resolution budget. You don't know if the input is landscape or portrait, you just know it shouldn't exceed some dimension - feed it in and this handles both. It's one of the most-used nodes in the pack for exactly that reason: real workflows take images of unknown shape and need to tame them without squashing faces.

How it works

It measures the longer of width/height, computes the scale factor that makes it equal your size, and applies that same factor to both dimensions. Proportions stay intact. It scales both up and down - if your image is smaller than size, it enlarges it (with the usual caveat that interpolation can't invent detail).

The inputs and outputs that matter

  • image (IMAGE) - the image (or batch) to resize.
  • size (INT, default 512) - the target length of the longer edge, in pixels. You can type it or wire it in; driving size from a computed INT (via a JWInteger or a math node) is a common pattern for making one control set the resolution across a graph.
  • interpolation_mode (enum: bicubic / bilinear / nearest / nearest exact) - bicubic is the smooth default for photos; bilinear is softer/faster; nearest keeps hard edges for pixel art or masks.
  • Output: IMAGE - the resized image, aspect ratio preserved.

How to install it

Part of jamesWalker55/comfyui-various, a pack of small utility nodes.

  • ComfyUI Manager: search "Various ComfyUI Nodes by Type", install, restart. Red node in a downloaded workflow? Install Missing Custom Nodes.
  • Manually:
    cd ComfyUI/custom_nodes
    git clone https://github.com/jamesWalker55/comfyui-various
    
    Restart afterward. No models, no dependencies.

Under the jamesWalker55 category after restart.

Common issues

  • The size input won't take a wire the way I expected. A real gotcha people hit: you can drive size from another node's INT output, but the widget has to be exposed as an input first (convert the widget to an input via right-click, then connect). If there's no socket to plug into, that's why. Once converted, feed it a JWInteger or a computed value.
  • The shorter side came out at an awkward number. Because the shorter edge is derived from the aspect ratio, it can land on a value that isn't divisible by 8 - which some models dislike. If that matters, follow this with a crop-to-resolution node or a small exact resize to snap it clean.
  • Wanted to constrain the shorter side, not the longer. Then you want the sibling node, JWImageResizeByShorterSide - it's the same logic anchored to the other edge.
  • Node is red / missing. The pack isn't installed. Install via Manager or clone the repo, then restart.

Longer-side is the "fit inside a box" resize; shorter-side is the "fill a box" resize. Pick based on whether you're capping the maximum dimension or guaranteeing the minimum.

CategoryjamesWalker55

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
sizeINT5120–99999
interpolation_modeCOMBO4 options: bicubic, bilinear, nearest, nearest exact

Outputs (1)

NameTypeDescription
IMAGEIMAGE