CalcFactorWidthHeight
The upscale-math helper that keeps your dimensions aligned
- width
- height
- large_side
- small_side
- width_float
- height_float
- large_side_float
- small_side_float
The node for "just multiply by 1.5 and make it a multiple of 64"
Hires-fix and upscale workflows are full of tedious arithmetic. You've got a 768×512 latent, you want to upscale it 1.5×, and the result has to stay aligned to a multiple of 8 or 64 or the VAE - or Flux - complains. That's the exact problem CalcFactorWidthHeight solves: give it width, height, and a factor, and it returns the scaled dimensions in two flavors - raw floats and ints snapped to a multiple you choose.
What it computes
The source is refreshingly transparent. It scales both sides by factor, keeps the un-rounded float versions, then produces integer versions. If your divide value is greater than 1, those ints get aligned to the nearest multiple of divide - rounding up when plus_divide is on (the default), rounding down when it's off.
So with divide=64 and plus_divide=true, 768×512 at factor 1.5 becomes 1152×768 exactly, and a fractional result like 1032.5 rounds up to 1088. With divide=1 (the default), no alignment happens - you just get int() of the floats.
The inputs
Four of them, and only two usually need touching:
width,height- the starting dimensions, often fromSizeToWidthHeightor your current latent size.factor- the multiplier, default1.5. The usual hires-fix sweet spot is 1.5–2×.divide- the alignment unit. Default1(no snapping). Set8for most VAE-decoded latents, or64on Flux.plus_divide- round up (true, default) or down (false) when snapping.
Outputs: why there are eight of them
The pack returns both the aligned ints and the raw floats, because each is useful:
width,height,large_side,small_side- integers, aligned, ready to feedEmpty Latent, an image resize, or a latent upscale node.width_float,height_float,large_side_float,small_side_float- the exact un-rounded numbers, handy when you want to see what alignment cost you.
The _float versions are the honest answer to "what would this be if I didn't have to round"; the ints are what you actually run.
A note on documentation
This is the quiet node in the pack - the README documents the other four and skips this one, so the code's docstring is the real source of truth. What it says, and what you should trust: a factor of 0 is treated as invalid, divide ≤ 1 means no alignment, and plus_divide controls up vs. down rounding. It's simple enough that "read the code" is a reasonable fallback, but you probably won't need to - the defaults work.
Install
It's in the same dependency-free repo as the rest:
cd ComfyUI/custom_nodes
git clone https://github.com/sugarkwork/ComfyUI_AspectRatioToSize
Restart ComfyUI, or grab it from ComfyUI Manager ("AspectRatioToSize"). No models, no pip installs.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| width | INT | — | |
| height | INT | — | |
| factor | FLOAT | 1.50 | — |
| divide | INT | 1 | — |
| plus_divide | BOOLEAN | true | — |
Outputs (8)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |
| large_side | INT | — |
| small_side | INT | — |
| width_float | FLOAT | — |
| height_float | FLOAT | — |
| large_side_float | FLOAT | — |
| small_side_float | FLOAT | — |