Nodes/ComfyUI Archon Nodes/Megapixels to Best Fit Resolution
ComfyUI Node

Megapixels to Best Fit Resolution

3 aspect? This node does the rounding you've been doing by hand

By esbe1175·Created 6 months ago·Updated 6 months ago· 1
Megapixels to Best Fit Resolution
    • width
    • height
    • applied_scale
    • actual_megapixels
    width832
    height1216
    megapixels1.50
    divisor64

    Every anime-model workflow eventually hits the same ritual: you know you want a certain resolution budget, and then you sit there mentally rounding numbers until they're a multiple of 64 and vaguely match your aspect ratio. That's the whole job of this node. Give it a target in megapixels plus the aspect ratio you want, and it returns the closest clean width/height - the exact pair you'd feed into an EmptyLatentImage.

    Why does this matter at all? Models have native resolution bands. SDXL and its anime descendants (Illustrious, NoobAI, Pony) are happiest around 1–1.5 megapixels, Anima likes roughly 1.3 (people report 1280 as the most coherent first pass), and the modern 1–2 MP band generally degrades softly rather than exploding if you overshoot - but your latents still want dimensions divisible by the model's tile size. "Just generate at 1.5 MP" isn't a number you can type; it's a constraint you have to resolve into pixels. This node resolves it.

    How it works

    The math is refreshingly sensible. It treats your input width and height purely as an aspect-ratio guide, computes the ideal dimensions for your target pixel count at that ratio (sqrt(megapixels * aspect)), rounds to the nearest multiple of divisor, then runs a small bounded search around that starting point - up to 80 steps in each direction - scoring every candidate on how far its pixel count and aspect ratio drift from the target. Pixel error is weighted ten times heavier than aspect error, because blowing the aspect ratio is worse than landing slightly above or below your megapixel budget.

    The inputs and outputs

    Four inputs, and only two really matter:

    • width / height (defaults 832×1216) - the aspect guide, not an absolute target. Change 832 to 800 and the output stays the same size; change the ratio and it pivots.
    • megapixels (default 1.5) - the actual budget. The number that decides everything.
    • divisor (default 64) - what the final dimensions snap to. Leave it at 64 for SDXL/Flux/Anima; drop it to 8 only if you're doing something exotic that tolerates odd multiples.

    Outputs: width and height as INTs (straight into EmptyLatentImage), plus two diagnostics - applied_scale, the ratio of output pixels to your original width/height, and actual_megapixels, the real pixel count after snapping. If you're feeding this into a hires pass, those two tell you what you actually got, which is rarely the round number you asked for.

    Installing it

    This is one of five nodes in the comfyui-archon-nodes pack, so installing it gets you all of them. ComfyUI Manager → search "Archon Nodes", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/esbe1175/comfyui-archon-nodes
    pip install -r ComfyUI/custom_nodes/comfyui-archon-nodes/requirements.txt
    

    Restart ComfyUI and it'll be under the Archon/Resolution category. Unlike its sibling in the pack, this node is pure Python - no models to download, no extra runtime beyond numpy/torch that ComfyUI already ships. The requests and cloudscraper deps in requirements.txt are there for the pack's Booru Roulette node, not this one.

    Gotchas

    • The width/height inputs don't set the resolution - they set the shape. People wire in their current canvas expecting it to resize, and get confused when the output only changes with megapixels.
    • Don't pair it with a divisor of 64 and then complain the output isn't the "trained ratio" your old SDXL checkpoint liked. For the 2024-era SDXL anime checkpoints, the discrete trained-ratio list (1024×1024, 1216×832, and friends) still matters more than a generic megapixel budget - for those, check the preset before trusting the math. For the newer megapixel-band models, this node is exactly right.

    It's a small, boring node, and that's the point: it replaces a fiddly manual calculation with something you can wire straight into your pipeline and forget about.

    CategoryArchon/Resolution

    Inputs (4)

    NameTypeDefaultDescription
    widthINT8321–65535
    heightINT12161–65535
    megapixelsFLOAT1.500.01–100
    divisorINT641–4096

    Outputs (4)

    NameTypeDescription
    widthINT
    heightINT
    applied_scaleFLOAT
    actual_megapixelsFLOAT