Nodes/ComfyUI-Flow-Assistor/Image Resolution Fit
ComfyUI Node

Image Resolution Fit

Resize an image to a megapixel target without breaking the aspect ratio

By Merserk·Created 9 months ago·Updated about a month ago· 6
Image Resolution Fit
  • image
  • latent
  • width
  • height
  • image
resolution_select1.00 MP (Reference: 1024x1024)

Image Resolution Fit resizes an incoming image toward a chosen megapixel target while preserving its aspect ratio, and hands you the resized image plus a matching empty latent and the new width/height. Where the pack's Resolution Extractor tells you what an image is, this node changes what it isn't quite - it's the "bring this image to a workable canvas size" step for img2img, and it solves the classic problem of feeding a 1342×893 photo into a pipeline that expects clean, model-friendly dimensions.

How it works

The mechanism is a simple geometric resize with model-friendly rounding. Pick a resolution_select tier (0.25, 0.6, 1, 2, 3, or 4 megapixels, referenced against square dimensions like 1024×1024), and the node computes a uniform scale factor so the image lands at roughly that total pixel count - larger side preserved, aspect ratio untouched. The result is rounded to the nearest multiple of 8 on both axes (the standard for diffusion latents, which are 8× downscaled), upscaled with Lanczos, and bundled with an empty latent sized to match.

Inputs:

  • image - any IMAGE tensor.
  • resolution_select - the megapixel tier. The default 1.00 MP is the right starting point for most SDXL and Flux work.

Outputs:

  • latent - an empty latent matching the resized canvas, ready to feed a sampler (though for img2img you'd typically encode the image instead; the latent is handy when you want a blank canvas at the same size).
  • width / height - the actual output dimensions, useful for downstream sizing logic.
  • image - the resized image itself.

The honest take: this is "more pixels," not "more detail"

Important to be clear-eyed about the distinction from the upscaling essay's taxonomy. This node is a pixel operation - it makes the image larger (or smaller) with Lanczos, it does not invent detail. If your source is sharp and you just need it at a bigger canvas, this is exactly right and free. If your source is soft and you're hoping for crispness, a geometric resize will disappoint you - what you want there is a generative restorer (SeedVR2, SUPIR) or tiled upscaling, which add real detail. Also note the resize can go down: feeding a 4K image into the 1MP tier downscales it, which is a legitimately useful move for img2img where oversizing a canvas invites tiling and repetition artifacts.

Installing

Part of ComfyUI-Flow-Assistor - ComfyUI Manager (search "Flow Assistor") or:

cd ComfyUI/custom_nodes
git clone https://github.com/Merserk/ComfyUI-Flow-Assistor.git

Restart after cloning. Current ComfyUI required (V3-only pack); no extra dependencies or model files.

Where people get burned

The megapixel tiers are referenced against square dimensions, so a 16:9 image at "1.00 MP" lands at a very different shape than a square one - that's fine and intended, but don't read "1.00 MP" as "1024×1024." And because the image output is Lanczos-resized rather than VAE-encoded, the empty latent output isn't a latent of the image; if you're building an img2img workflow, VAE-encode the resized image output yourself. Rounding to multiples of 8 means the final dimensions won't exactly equal your target megapixels - that's the point, and it's what makes the result model-friendly.

Categoryflow-assistor/image

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
resolution_selectCOMBO1.00 MP (Reference: 1024x1024)6 options: 0.25 MP (Reference: 512x512), 0.60 MP (Reference: 768x768), 1.00 MP (Reference: 1024x1024), 2.00 MP (Reference: 1408x1408), 3.00 MP (Reference: 1728x1728), 4.00 MP (Reference: 2048x2048)

Outputs (4)

NameTypeDescription
latentLATENT
widthINT
heightINT
imageIMAGE