Nodes/ComfyUI-ResolutionHelper/Resolution from Megapixels
ComfyUI Node

Resolution from Megapixels

Resolution from Megapixels

By AlfredSartan572·Created 22 days ago·Updated about 12 hours ago· 1
Resolution from Megapixels
    • width
    • height
    • longest
    ◄aspect_ratio▾►
    ◄megapixels1.0000►
    ◄multiple32►

    Why you'd want this

    Every default ComfyUI graph hands you an Empty Latent Image with two number boxes, and you are the one doing the arithmetic. 512 and 512 is fine. Widen it and now you're guessing whether 1216x832 is a real trained bucket or a number you made up at 11pm.

    It matters because resolution is not a free parameter. SDXL was trained at 1024x1024 plus a handful of buckets (1024x1024, 1152x896, 1216x832, 1344x768, 1536x640, and their rotations), and Pony and Illustrious inherit that. Feed an SDXL-family checkpoint a random 1920x1080 and you get stretched anatomy - the "why does she have two heads" genre. By 2026 the constraint has loosened a lot: most current models take anything in a 1–2 megapixel band and fail softly, by going dull, rather than structurally. Which is an argument for thinking in megapixels to begin with. "About a megapixel, shaped like this" is now a closer description of what models want than a magic pair of integers.

    This node is that sentence, as a node. Pick an aspect ratio, pick a megapixel budget, get two integers back that you can wire straight into the latent.

    The math it actually does

    It's about six lines of Python, and reading them is worth it because the rounding is where the surprises live:

    width  = floor( sqrt(megapixels * 1024*1024 * aspect_w / aspect_h) / step ) * step
    height = floor( (width * aspect_h / aspect_w) / step ) * step
    

    So width is solved from the megapixel target, then height is derived from width, and both get floored down to the nearest multiple of step. One detail: 1024*1024 is 1,048,576, so "1.0 megapixels" here is 1.048M pixels - binary megapixels, not the 1,000,000 kind. Close enough to not care, but it's why the numbers aren't round.

    Two consequences you'll actually feel:

    | Setting | Result | Real MP | |---|---|---| | 1:1, 1.0 MP | 1024x1024 | 1.00 | | 16:9, 1.0 MP, step 32 | 1344x736 | 0.94 | | 16:9, 1.0 MP, step 64 | 1344x704 | 0.90 | | 16:9, 1.1 MP, step 64 | 1408x768 | 1.03 |

    Because everything floors, you land at or below the budget you asked for, sometimes by a full step. Square ratios land exactly. Wide ones quietly lose five to ten percent. If your model has a hard floor at 1 MP - plenty of the Flux-family and the newer Z-Image crowd do - set megapixels a little above 1.0 rather than at it.

    The inputs and outputs that matter

    Three inputs, all required, all widgets:

    • aspect_ratio - 15 presets, and the pack lists every rotation rather than making you flip your own. Landscape gets 32:9, 21:9, 16:9, 16:10, 5:4, 4:3, 3:2; portrait gets the mirrored 9:32, 9:21, 9:16, 10:16, 4:5, 3:4, 2:3, plus 1:1 in the middle.
    • megapixels - default 1.0, range 0.05 to 50. This is your whole size dial.
    • step - the multiple everything snaps to. Default 32, range 1 to 112, and the author's own tooltip is refreshingly specific: "MiniMaxH3=32, Illustrious/Pony=64, other=16". Believe it. 64 is the SDXL-family habit; 16 is the safe general default; video and newer architectures mostly want 32.

    Three outputs, all INT: width, height, and longest. The first two go into Empty Latent Image - right-click its width and height widgets and use "Convert widget to input" so they become sockets. longest is the long edge, which is the number a lot of resize and upscale nodes actually want, so it's the one you wire downstream when you're, say, scaling an existing image to match your new generation.

    The pack ships three siblings you'll want to know about: Resolution Calculator does the same trick from an input image's own aspect ratio, and Aspect Ratio Selector exists so you can pick a ratio once and wire the same choice into more than one of these nodes instead of setting it twice and getting it wrong once.

    Installing it

    ComfyUI Manager, search for ResolutionHelper or the pack title ComfyUI-ResolutionHelper, install, restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/AlfredSartan572/ComfyUI-ResolutionHelper
    # restart ComfyUI
    

    There is nothing else to do. No requirements.txt, no model downloads, and pyproject.toml declares no dependencies at all - the only import in the whole pack is Python's stdlib math. Nodes land under the Resolution Tools category.

    That's also the honest answer to "should I trust this one." It's brand new, one author, published to the Comfy Registry in late September 2026, with essentially no community discussion yet. It's also around 200 lines of arithmetic that installs nothing, so it cannot break your environment. Fresh, tiny and inert is a different risk profile from fresh and pip-installing twelve things.

    Where people get burned

    Wrong step for your model. The default 32 is a fine general answer and the wrong answer for Pony/Illustrious checkpoints, which expect 64. Nothing will crash - you'll just get a slightly soft image and blame the checkpoint.

    Expecting exact SDXL buckets. The ratio list is human ratios, not the trained buckets. 7:4 (1344x768) isn't in it, so you can't dial that one in directly; you'd get 1344x704 at 1.0 MP and step 64. If you need an exact bucket, the node isn't the tool - or bump the megapixels and accept a near-miss.

    Thinking this resizes anything. It doesn't touch pixels. It computes two integers. If the graph downstream still has old dimensions baked in - a second latent, a fixed size on an upscaler - the node is doing nothing and you'll wonder why your change had no effect.

    CategoryResolution Tools

    Inputs (3)

    NameTypeDefaultDescription
    aspect_ratioCOMBO15 options: 32:9 (Super Ultrawide), 21:9 (Ultrawide), 16:9 (Widescreen), 16:10 (WUXGA), 5:4 (5:4 Standard), 4:3 (Standard), +9
    megapixelsFLOAT1.00000.05–50—
    multipleINT321–112MiniMaxH3=32, Illustrious/Pony=8, other=16

    Outputs (3)

    NameTypeDescription
    widthINT—
    heightINT—
    longestINT—