Scale To Resolution JK๐
Get the right dimensions before you resize
- image
- latent
- target_width
- target_height
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 -
directionpicks width or height, andtarget_resolutionis the size for that side. The other side is scaled to preserve the aspect ratio. - Megapixel mode - turn on
use_target_mega_pixeland it scales the whole image so the total pixel count lands neartarget_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 Imagenode. That's the whole design. - Rounding changes the aspect ratio slightly.
multiple_ofrounding 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, dropmultiple_ofto 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.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| direction | BOOLEAN | false | โ |
| target_resolution | INT | 5128โ16384 | โ |
| use_target_mega_pixel | BOOLEAN | false | โ |
| target_mega_pixel | FLOAT | 1.000.01โ16 | โ |
| multiple_of | INT | 80โ16 | โ |
| imageopt | IMAGE | โ | |
| latentopt | LATENT | โ |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| target_width | INT | โ |
| target_height | INT | โ |