Image Size Matcher
Pick a latent size that actually matches your image's aspect ratio
- image
- width
- height
- size_string
- aspect_ratio
Every img2img, inpaint, or outpainting workflow has the same awkward moment: you've got an image at one aspect ratio, you need an empty latent at the right size for the model, and you're typing 1024x1024 while crossing your fingers. This node removes the guesswork. It reads the aspect ratio of an image, compares it against a list of preset sizes you define, and outputs the closest match as numbers - not a resized image, just the dimensions.
How it works
ImageSizeMatcher takes the input tensor's width and height, computes the aspect ratio, then walks your preset_sizes list and scores each candidate by how far its own aspect ratio diverges. The closest wins, and the node reports four outputs: width, height, size_string (like 768x512), and aspect_ratio (simplified to something like 3:2). The ratio comparison means a landscape 1.4-ratio image picks 768x512 over 1024x1024 - it's matching shape, not resolution, which is exactly what you want when deciding what latent to generate into.
Preset sizes go one per line, and the parser is forgiving: 512x768, 512*768, 512 × 768, even comma-separated all work. Keep the list realistic for your checkpoint's native resolution, since the node only tells you which preset matches - it doesn't validate that the size is actually good for SDXL versus Flux.
The inputs that matter
- image - the reference. Wire in your loaded image, a VAE-decoded result, or anything you want to match.
- preset_sizes - the multiline list you want to choose from. Default is
512x768 / 512x512 / 1024x1024 / 768x512 / 1024x768, which is a decent starting menu for SD 1.5 and SDXL alike.
Outputs are plain INT and STRING values, so they're not visual. The classic pattern: feed width and height into an EmptyLatent (or a size-preset node), then img2img at low denoise into that latent so your output comes out at the same aspect as the input without distortion.
Installing it
Part of ComfyUI-YCNodes. ComfyUI Manager → search ComfyUI-YCNodes → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes
Restart after cloning. No heavy dependencies beyond what ComfyUI already has (torch, numpy, pillow, opencv-python, scipy in the pack's requirements).
Gotchas
The one real trap: it matches aspect ratio, not pixel count. If your list has both 1024x1024 and 896x1152, a square image picks 1024x1024 - good - but a near-square 800x832 also picks the 1:1 square, and you might have wanted the smaller option to save VRAM. Order in the list doesn't break ties in your favor, so put the size you'd rather have used earlier in the list and test. Also note it's the mirror image of the pack's ImageAspectExpand: that node changes the canvas to a ratio, this one just tells you which of your sizes already matches. Between them, you can build an outpainting prep that's actually deterministic instead of "eh, close enough."
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| preset_sizes | STRING | 512x768 512x512 1024x1024 768x512 1024x768 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |
| size_string | STRING | — |
| aspect_ratio | STRING | — |