Nodes/DJZ-Nodes/Image Size Adjuster
ComfyUI Node

Image Size Adjuster

The 'what size should my latent be' calculator

By MushroomFleet·Created 2 years ago·Updated 5 months ago· 78
Image Size Adjuster
  • image
  • adjusted_width
  • adjusted_height
model_type
downscale_factor64

Every model family has a pixel-count sweet spot: SD wants ~512×512, SDXL wants ~1024×1024, Cascade-class wants a lot more. But you've got an input image with some random aspect ratio, and you need to know what dimensions to generate at so you keep the ratio and hit the model's comfort zone. ImageSizeAdjuster is a two-output calculator that answers exactly that question - it computes target width and height for you, pre-rounded so your latent is clean. No resizing happens here; this node just gives you the numbers to feed an empty latent.

How it works

It reads the input image's actual dimensions from the tensor (image.shape), computes the aspect ratio, then picks a target total pixel count from a small internal table based on model_type:

  • SD → 512×512 = 262,144 total pixels
  • SDXL → 1024×1024 = 1,048,576
  • Cascade → 2048×2048 = 4,194,304

Then it solves for new_width = sqrt(target_pixels * aspect_ratio), derives the matching height, and rounds both up to the nearest multiple of downscale_factor (default 64, up to 128). Outputs are adjusted_width and adjusted_height - two INTs, not an image. Wire them into an Empty Latent node's width/height, or into any node that takes dimension inputs.

So the workflow is: LoadImage → ImageSizeAdjuster → (width, height) → EmptyLatentImage → KSampler. You get the source's composition preserved, at the right pixel budget, with dimensions your VAE and sampler will happily accept.

The inputs

Three: image (IMAGE), model_type (SD / SDXL / Cascade), downscale_factor. That's the whole schema. The rounding is always up to a multiple, so you'll land slightly above the target budget rather than under - an intentional choice that keeps you from undersizing a latent.

Installing

Part of DJZ-Nodes (Drift Johnson / MushroomFleet):

cd ComfyUI/custom_nodes
git clone https://github.com/MushroomFleet/DJZ-Nodes
cd DJZ-Nodes
pip install -r requirements.txt

Or search "DJZ-Nodes" in ComfyUI Manager. Pure math, no deps.

Honest notes

This is a calculator, and it doesn't look at content - a 16:9 landscape photo and a 9:16 portrait shot get different numbers because the ratio differs, but both respect the pixel budget. The Cascade preset assumes the very generous 2048×2048 budget, which is way beyond what most local setups can sample; pick SDXL unless you're genuinely running a Cascade-class model on a big card. And be careful rounding up repeatedly: if you're chaining this into a batch pipeline that also applies aspect-ratio constraints, you can creep past VRAM limits. For most people it's a one-node fix for "what size do I generate?" that replaces a calculator app and a hunch.

CategoryDJZ-Nodes

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
model_typeCOMBO3 options: SD, SDXL, Cascade
downscale_factorINT641–128

Outputs (2)

NameTypeDescription
adjusted_widthINT
adjusted_heightINT