Nodes/optimal-crop-resolution/Resolution Matcher
ComfyUI Node

Resolution Matcher

Snap to the exact resolution your model was trained on

By hodanajan·Created 2 years ago·Updated 2 years ago· 2
Resolution Matcher
    • width
    • height
    width1024
    height1024
    use_sd15_1:1_512x512false
    use_sd1.5/sdxl_1:1_768x768false
    use_sd15_3:2_768x512false
    use_sd15_2:3_512x768false
    use_sd15_4:3_768x576false
    use_sd15_3:4_576x768false
    use_sd15_16:9_912x512false
    use_sd15_9:16_512x912false
    use_sdxl_1:1_1024x1024false
    use_sdxl_3:2_1152x768false
    use_sdxl_2:3_768x1152false
    use_sdxl_4:3_1152x864false
    use_sdxl_3:4_864x1152false
    use_sdxl_16:9_1360x768false
    use_sdxl_9:16_768x1360false
    use_flux_1:1_1408x1408false
    use_flux_3:2_1728x1152false
    use_flux_4:3_1664x1216false
    use_flux_16:9_1920x1088false
    use_flux_21:9_2176x960false
    custom_resolutions

    Its sibling node, Aspect Ratio Calculator, matches against generic ratios like 16:9 or 3:2. This one skips the abstraction and matches against a curated table of actual resolutions specific models were trained at - SD1.5's 512x512, SDXL's 1024x1024/1152x768/1360x768 family, Flux's 1408x1408 up through 2176x960. If you've ever wondered why some generations look subtly off even though the aspect ratio seems reasonable, this is usually the fix: it's not enough to get the ratio right, you want the exact pixel count the model actually saw during training, or something very close to it.

    Why this matters

    Every architecture has a resolution it's comfortable at, and going outside it is the single most common cause of the "why does this look warped" complaints - duplicated limbs, tiled backgrounds, extra heads. SD1.5 wants 512x512 (768x768 with some quality loss); SDXL wants ~1024x1024 or one of a handful of sibling ratios; Flux is more flexible but still clusters around 1024–2MP, in dimensions divisible by 64. Those aren't arbitrary numbers - they're what shows up in this node's checkbox list, split cleanly by model family so you're not eyeballing which of SDXL's odd 1152x864-style dimensions is closest to what you need.

    How it works

    Same shape as its sibling: give it your current width and height (both plain integers, defaulting to 1024x1024 - normally you'd wire these from a Get Image Size node upstream rather than typing them in), and it returns the closest resolution from whichever entries you've switched on.

    The catch, and it's worth knowing before you drop this into a graph: every single resolution checkbox defaults to off. Unlike Aspect Ratio Calculator, which ships with all seven standard ratios enabled, Resolution Matcher gives you nothing until you go pick some. The full list is long - eight SD1.5 options (use_sd15_1:1_512x512, use_sd15_3:2_768x512, use_sd15_16:9_912x512, and their rotations/variants, plus one SD1.5/SDXL-shared 768x768), eight SDXL options across 1:1, 3:2, 4:3, and 16:9 (and their portrait rotations), and five Flux options up to a 21:9 ultrawide at 2176x960. In practice you switch on just the family you're actually generating with - flipping on Flux entries while running an SDXL checkpoint just gives it irrelevant candidates to compare against. There's also custom_resolutions, a string field, if none of the built-in entries fit.

    Outputs

    Two, both INT: width and height - the matched target resolution, full stop. No ratio breakdown here (that's the other node's job); this one hands you a resolution you plug straight into whatever resizes, crops, or sets your latent size downstream.

    Installing it

    Same pack as Aspect Ratio Calculator, same install, same lack of baggage. The README is a single line - no dependencies, no model downloads, nothing to configure beyond the node itself. ComfyUI Manager: search optimal-crop-resolution, install, restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/hodanajan/optimal-crop-resolution
    

    Restart ComfyUI; it lands under image/resolution next to Aspect Ratio Calculator.

    Where people get tripped up

    The big one: drop this node into a graph, leave every checkbox at its default (all off), and it has nothing to match against - you'll get back whatever your raw input was, because there's no candidate list to compare it to. That's almost certainly not a bug, it's just an unticked box; go enable the resolutions for the model family you're actually using. Second, don't mix families carelessly - enabling Flux resolutions for an SD1.5 workflow will "successfully" match you to a resolution your checkpoint has never seen and wasn't built for, which defeats the entire point of the node. And as with its sibling, this is a pure calculator: nothing happens to your image until you take its width/height outputs and actually wire them into a resize or empty-latent node.

    Categoryimage/resolution

    Inputs (23)

    NameTypeDefaultDescription
    widthINT10241–8192
    heightINT10241–8192
    use_sd15_1:1_512x512optBOOLEANfalse
    use_sd1.5/sdxl_1:1_768x768optBOOLEANfalse
    use_sd15_3:2_768x512optBOOLEANfalse
    use_sd15_2:3_512x768optBOOLEANfalse
    use_sd15_4:3_768x576optBOOLEANfalse
    use_sd15_3:4_576x768optBOOLEANfalse
    use_sd15_16:9_912x512optBOOLEANfalse
    use_sd15_9:16_512x912optBOOLEANfalse
    use_sdxl_1:1_1024x1024optBOOLEANfalse
    use_sdxl_3:2_1152x768optBOOLEANfalse
    use_sdxl_2:3_768x1152optBOOLEANfalse
    use_sdxl_4:3_1152x864optBOOLEANfalse
    use_sdxl_3:4_864x1152optBOOLEANfalse
    use_sdxl_16:9_1360x768optBOOLEANfalse
    use_sdxl_9:16_768x1360optBOOLEANfalse
    use_flux_1:1_1408x1408optBOOLEANfalse
    use_flux_3:2_1728x1152optBOOLEANfalse
    use_flux_4:3_1664x1216optBOOLEANfalse
    use_flux_16:9_1920x1088optBOOLEANfalse
    use_flux_21:9_2176x960optBOOLEANfalse
    custom_resolutionsoptSTRING

    Outputs (2)

    NameTypeDescription
    widthINT
    heightINT