Nodes/ComfyUI-PixelResolutionCalculator/PixelResolutionCalculator
ComfyUI Node

PixelResolutionCalculator

Megapixels and Aspect Ratio In, Latent-Friendly Dimensions Out

By Ling-APE·Created 2 years ago·Updated about a year ago· 8
PixelResolutionCalculator
    • width
    • height
    megapixels2.00
    aspect_ratio_width3
    aspect_ratio_height4
    divided_by8

    If you've moved from SDXL to Flux, you've hit the switch: nobody talks about width and height anymore, they talk about megapixels and aspect ratio. "2 megapixel, 3:4" is the new "1216x832". That's all well and good until you actually have to type numbers into ComfyUI, because the pixel dimensions have to be a multiple of 8 to not corrupt the latent, and doing that arithmetic in your head at 1am is exactly how you end up with a 1220x1634 image that produces a black screen. This node is the tiny calculator that fixes that.

    PixelResolutionCalculator is a pure-math utility from ComfyUI-PixelResolutionCalculator, the companion pack to Ling-APE's popular All-in-One Flux Dev workflow (the one that got ~180 upvotes on r/StableDiffusion back in August 2024). The README credits the idea to the ImageScaleToTotalPixels node in the original official Flux demo workflow - same "think in total pixels" philosophy, packaged as a standalone generator instead of a resizer.

    How it works

    Feed it a megapixel target and an aspect ratio, and it solves for width and height, then snaps both to the nearest multiple of divided_by. The math: it reduces your aspect ratio by the GCD, finds the scale factor that makes width × height equal your megapixel count, and floors the results.

    There's a subtlety worth knowing: it rounds down, not to the nearest multiple. So the output is "closest at or below your target", and your actual resolution can land a hair under the megapixels you asked for. For a 2MP 3:4 request it's basically exact (1224×1632), but don't be surprised if a weird ratio like 5:7 comes back a touch smaller. Treat it as "close enough that the model can't tell" rather than a guarantee.

    The inputs that matter

    Only four, and all required:

    • megapixels (float, default 2.0) - your target total pixels. The 2.0 default is no accident: Flux is comfortable up to around 2 megapixels (1536×1536 and change) before quality degrades.
    • aspect_ratio_width and aspect_ratio_height (ints, defaults 3 and 4) - the two halves of your ratio. 3:4 gives portrait, 4:3 landscape, 16:9 widescreen.
    • divided_by (int, default 8) - the divisibility requirement. 8 is the safe floor for most VAEs; some Flux workflows ask for 64. If you're feeding a model with a stricter constraint, raise it.

    The two outputs, width and height (both INT), wire straight into an EmptyLatentImage's width and height inputs - that's the entire intended use, and it's exactly how the author wires it in their workflow behind a resolution switch. You could also feed them into any other node that takes pixel INTs, like a resize target.

    Installing it

    The pack has zero dependencies - no requirements.txt, no model downloads, no llama.cpp. It's two small Python classes. Easiest route: ComfyUI Manager → "Install Custom Nodes" → search ComfyUI-PixelResolutionCalculator → Install → restart ComfyUI. Or do it by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Ling-APE/ComfyUI-PixelResolutionCalculator
    

    Restart ComfyUI and the node appears under the image category.

    Common issues

    Honestly, there isn't much to trip on here. The recurring beginner mistake is misunderstanding that the result is approximate: the node floors to keep divisibility, so the total pixel count is slightly under your megapixel target, not exactly on it. The other gotcha is forgetting that "latent-friendly" only means "divisible by whatever you set in divided_by" - if you drop it to 1 to get exact dimensions, you've silently disabled the protection the node exists to provide. Keep it at 8 (or your model's stricter requirement) and let it do the rounding.

    Categoryimage

    Inputs (4)

    NameTypeDefaultDescription
    megapixelsFLOAT2.000.1–100
    aspect_ratio_widthINT31–100
    aspect_ratio_heightINT41–100
    divided_byINT81–100

    Outputs (2)

    NameTypeDescription
    widthINT
    heightINT