Find Perfect Resolution
It does your aspect-ratio math so your latent sizes stop erroring
- image
- mask
- width
- height
- IMAGE
- mask_output
- resolution_info
Every ComfyUI user has had this moment: you want to feed a 4:5 photo into a workflow at roughly a megapixel, keep the aspect ratio, and stay on a size the VAE actually accepts - so you fire up a calculator, do the multiplication, and round by hand. Find Perfect Resolution is that calculation, packaged as a node. Give it an image and a target ballpark, and it hands back a width and height that preserve the ratio, hit close to your target pixel count, and land exactly on a value you specify.
How it works
The logic is refreshingly transparent. It reads the source image's actual dimensions, then treats desired_width × desired_height as a target pixel budget. From there it's one formula: h = round(sqrt((target_pixels × orig_h) / orig_w) / divisible_by) * divisible_by, and width follows from the aspect ratio. Set one of the desired dimensions to 0 and it derives it from the other using the image's real ratio - handy when you only care about one side. Set both to 0 and it raises an error, which is its way of telling you it can't guess the aspect ratio from nothing.
Beyond the numbers, it can also resize the image itself using Pillow (lanczos by default). Nice touch for a utility: it shows the computed result live under the node as you drag the sliders.
The inputs that matter
Only a few of these do you actually touch:
- image (required) - anything from a Load Image node. Its aspect ratio is the thing being preserved.
- desired_width / desired_height - the target.
0means "derive from the other one." Note the code's default is0(auto), not the 512 the README still claims; source wins. - divisible_by - the grid you snap to. Default
16, which is right for most SD/SDXL work. If you're feeding a Flux model, bump it to64- Flux wants multiples of 64, and this node will happily enforce that so you never hit the mismatch errors downstream.
The rest are optional and mostly self-explanatory: upscale (off by default), upscale_method, small_image_mode for tiny inputs (crop or pad, with pad_color to set the fill), and a mask input so an inpaint mask gets the exact same treatment.
The outputs
You get five. The two that matter are width and height (both INT) - wire those into a Resize Image v2, an Empty Latent, or a Latent Upscale and your workflow is automatically on-grid. There's also the resized IMAGE (kept at its original size if the target would be an upscale and upscale is off - you'll still get the numbers), a mask_output resampled with nearest-neighbor so hard mask edges stay sharp, and a resolution_info string like 1024x1344 | 4.11MB | 1,376,256 pixels if you want the stats in a text box.
Installing and a word of caution
Install is as painless as it gets: in ComfyUI Manager, search for comfyui-find-perfect-resolution, or
cd ComfyUI/custom_nodes
git clone https://github.com/ashtar1984/comfyui-find-perfect-resolution
then restart. There are no model downloads and no extra pip dependencies beyond torch and Pillow, which ComfyUI already ships. Be honest about what this is, though: the pack is brand new (a single commit) with basically no community footprint, so don't expect a support forum. The formula itself is dead simple and verifiable - that's the whole appeal. If you're sick of eyeballing resolutions and getting "latent shape mismatch" for it, this is a fine fix; if you just resize by hand occasionally, it's a nice-to-have, not a must-have.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| desired_width | INT | 00–8192 | — |
| desired_height | INT | 00–8192 | — |
| divisible_by | INT | 161–128 | — |
| maskopt | MASK | — | |
| upscaleopt | BOOLEAN | false | — |
| upscale_methodopt | COMBO | lanczos | 4 options: lanczos, bilinear, bicubic, nearest |
| small_image_modeopt | COMBO | none | 3 options: none, crop, pad |
| pad_coloropt | STRING | #000000 | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |
| IMAGE | IMAGE | — |
| mask_output | MASK | — |
| resolution_info | STRING | — |