Nodes/Skycoder Tools/Image Advanced Resize
ComfyUI Node

Image Advanced Resize

Resize, grayscale, and get your aspect ratio as a bonus

By skycoder182·Created about a year ago·Updated about a year ago· 1
Image Advanced Resize
  • image
  • width
  • height
  • ratio
  • aspect_type
  • aspect_ratio_common
  • output_image
resizefalse
grayscalefalse
keep_aspect_ratiotrue
resize_modeby_megapixel
target_megapixel1.0
new_width256
new_height256
divisible_by1

Image Advanced Resize is a Swiss-army preprocessing node: it resizes an image (by target megapixels or by explicit dimensions), optionally converts it to grayscale, and alongside the processed image hands you a stack of metadata - width, height, ratio, landscape/portrait/square, and a human-readable 16:9-style ratio. One node replaces what would otherwise be several.

The two modes cover the two resize jobs people actually have. By megapixel is the modern one: you tell it "I want this to be a 1 MP image" and it keeps the aspect ratio and lands right at that size - exactly what you want when normalizing a batch of images to a model's native resolution (SDXL territory, Flux territory, whatever). By dimensions is the classic fit-to-box resize: give it a max width and height and it scales to fit, respecting the aspect ratio unless you tell it not to. There's even a divisible_by option (1/2/4/8/16/32/64) to round the result to a latent-friendly multiple, which saves you the "the VAE hates odd dimensions" headache later.

How it works

The image comes in as a ComfyUI tensor, gets converted to PIL, and - if you've ticked resize - resized with LANCZOS. The by-megapixel path solves for dimensions that hit your target MP at the source's aspect ratio; the by-dimensions path fits within your width/height box. Then rounding to divisible_by happens as nearest multiple, and the result is converted back to a tensor. Grayscale is a straightforward per-pixel luminance conversion. Finally it computes the ratio and a greatest-common-divisor-reduced w:h label.

One implementation quirk worth knowing: the grayscale pass is a plain Python loop over pixels, not vectorized. Fine for a single image, but don't batch a thousand large frames through it and expect speed.

Inputs and outputs

The ones you'll actually set:

  • image (IMAGE) - required input.
  • resize (BOOLEAN, default false) - the master switch. Off by default, which means the node is a metadata pass-through until you tick it.
  • resize_mode (enum, default by_megapixel) - by_dimensions or by_megapixel.
  • target_megapixel (FLOAT, default 1) - used in by-megapixel mode.
  • new_width / new_height (INT, default 256) - used in by-dimensions mode.
  • divisible_by (enum, default 1) - rounding multiple.
  • grayscale (BOOLEAN, default false), keep_aspect_ratio (BOOLEAN, default true).

Outputs: width/height (INT), ratio (FLOAT), aspect_type (STRING: landscape/portrait/square), aspect_ratio_common (STRING like "16:9"), and output_image (IMAGE) - the processed image, which is the only output you'd normally wire onward. The metadata outputs are handy for driving other nodes: feed width/height into an Empty Latent, or log aspect_ratio_common to a text node.

Installing it

Part of the Skycoder Tools pack:

cd ComfyUI/custom_nodes
git clone https://github.com/skycoder182/comfyui-skycoder-tools.git
# then restart ComfyUI

Or ComfyUI Manager → "Install Custom Nodes" → search "Skycoder Tools" → Install → restart. No models, no extra dependencies.

Common issues

The top gotcha is the resize default: it's off, so if you wire this in expecting a resized image and nothing changes, check that checkbox first. Second, rounding is to the nearest multiple, not down, so divisible_by can push a result slightly above your target - usually fine, occasionally surprising if you were sizing for a tight VRAM budget. And keep the slow grayscale loop in mind before you point it at a big batch.

CategoryBeispiele/Bild

Inputs (9)

NameTypeDefaultDescription
imageIMAGE
resizeBOOLEANfalse
grayscaleBOOLEANfalse
keep_aspect_ratioBOOLEANtrue
resize_modeCOMBOby_megapixel2 options: by_dimensions, by_megapixel
target_megapixeloptFLOAT1.0
new_widthoptINT2561–4096
new_heightoptINT2561–4096
divisible_byoptCOMBO17 options: 1, 2, 4, 8, 16, 32, +1

Outputs (6)

NameTypeDescription
widthINT
heightINT
ratioFLOAT
aspect_typeSTRING
aspect_ratio_commonSTRING
output_imageIMAGE