Nodes/ComfyUI-JakeUpgrade/Scale To Resolution JK๐Ÿ‰
ComfyUI Node

Scale To Resolution JK๐Ÿ‰

Get the right dimensions before you resize

By jakechaiยทCreated 2 years agoยทUpdated 3 months agoยท 146
Scale To Resolution JK๐Ÿ‰
  • image
  • latent
  • target_width
  • target_height
โ—„directionfalseโ–บ
โ—„target_resolution512โ–บ
โ—„use_target_mega_pixelfalseโ–บ
โ—„target_mega_pixel1.00โ–บ
โ—„multiple_of8โ–บ

Most "scale to resolution" nodes resize the image. This one doesn't - it computes the target dimensions and hands you two integers. That sounds like a downgrade until you realize the use case: you want to scale an image to a target width or height while preserving aspect ratio, then feed the resulting numbers into a latent-size node, a resize node, or a KSampler that needs explicit dimensions. Doing that arithmetic in your head, or with floating-point drift, is exactly how you get a "shape mismatch" error two nodes later.

How it works

You give it a source - the optional image or latent input - and a target. The source sets the starting width/height (an image's pixel dims, or a latent's dims multiplied by 8 for the pixel equivalent). If neither is connected, it assumes a 1024ร—1024 source, so the node still returns something rather than crashing.

Then one of two modes applies:

  • Target dimension mode - direction picks width or height, and target_resolution is the size for that side. The other side is scaled to preserve the aspect ratio.
  • Megapixel mode - turn on use_target_mega_pixel and it scales the whole image so the total pixel count lands near target_mega_pixel (default 1.0 MP).

multiple_of (default 8) rounds both dimensions up to a multiple of 8, which matters because diffusion latents and most encoders want dimensions divisible by 8 (or 16/64 for video). Set it to 0 to disable rounding.

Inputs and outputs

  • image / latent - optional, the source whose proportions you're scaling.
  • direction - scale by width or by height.
  • target_resolution - the size of the chosen side.
  • use_target_mega_pixel / target_mega_pixel - the megapixel mode.
  • multiple_of - rounding grid.
  • target_width, target_height - the two integers you wire into a resize or latent node.

Installing it

Ships in ComfyUI-JakeUpgrade:

  • ComfyUI Manager โ†’ search "JakeUpgrade" โ†’ install โ†’ restart.
  • Or:
cd ComfyUI/custom_nodes
git clone https://github.com/jakechai/ComfyUI-JakeUpgrade
cd ComfyUI-JakeUpgrade
pip install -r requirements.txt

Windows portable: run install.bat or ../../../python_embeded/python.exe -s -m pip install -r requirements.txt.

Common issues

  • It doesn't resize anything. The most common "it's broken" report is actually a mismatch of expectations: the output is two integers, not an image. You feed those integers into an actual resize or Empty Latent Image node. That's the whole design.
  • Rounding changes the aspect ratio slightly. multiple_of rounding is one reason your "exact" 16:9 comes out 1344ร—768 instead of 1280ร—720 - the numbers get snapped to the grid. Usually fine; if you need pixel-exact ratios, drop multiple_of to 0.
  • Latent vs image source confusion. Feeding a latent multiplies by 8 internally to report pixel dimensions, which is correct. Feeding the decoded image when you meant the latent (or vice versa) doubles the numbers.

If you're hand-wiring resolutions, you don't need it. If you're building a workflow where a user picks a target size and everything downstream must agree, this node is the single source of truth for the numbers.

Category๐Ÿ‰ JK/๐Ÿ›ฉ๏ธ Image

Inputs (7)

NameTypeDefaultDescription
directionBOOLEANfalseโ€”
target_resolutionINT5128โ€“16384โ€”
use_target_mega_pixelBOOLEANfalseโ€”
target_mega_pixelFLOAT1.000.01โ€“16โ€”
multiple_ofINT80โ€“16โ€”
imageoptIMAGEโ€”
latentoptLATENTโ€”

Outputs (2)

NameTypeDescription
target_widthINTโ€”
target_heightINTโ€”