Nodes/ComfyUI_EmAySee_CustomNodes/EmAySee VAE-Compatible Aspect Ratio Calculator
ComfyUI Node

EmAySee VAE-Compatible Aspect Ratio Calculator

Match a reference image's aspect ratio without tripping the VAE

By EmAySee·Created about a year ago·Updated 4 months ago· 2
EmAySee VAE-Compatible Aspect Ratio Calculator
  • image
  • output_width
  • output_height
output_height512

If you've ever piped an input image into a workflow and just wanted the output to be the same shape, you know the manual math: pick a height, multiply by the aspect ratio, then round to something the VAE won't choke on. The EmAySee VAE-Compatible Aspect Ratio Calculator is that step in node form. You feed it an image and a target height, and it hands back a width (and that height) that keeps the original aspect ratio while staying on a VAE-safe grid.

Why the "VAE-compatible" part matters: the VAE downsamples the latent by 8x per side, so dimensions that aren't multiples of 8 cause errors or silent weirdness, and in practice you want multiples of 64 - the step the SDXL/Flux latents actually like. This node rounds the width to the nearest multiple of 64, so the numbers it produces drop straight into an Empty Latent Image node without you doing arithmetic.

The inputs are just two:

  • image - any IMAGE tensor. It only reads the shape of the first frame in the batch, so feed it the reference whose aspect ratio you want to match.
  • output_height - the height you want (default 512). The UI presents it as a dropdown of sane values (512, 576, 640, 704, 768, 832, 896, 960, 1024) with a 64 step, so it'll usually snap to the grid for you.

How it works is delightfully small: it reads the image's width and height, computes ratio = width / height, then output_width = round(output_height * ratio / 64) * 64. Your chosen height comes back unchanged. That's the whole thing - no VAE is loaded, nothing is rendered, no model involved.

How to install

It's part of the one-pack install, same as every node here:

cd ComfyUI/custom_nodes
git clone https://github.com/EmAySee/ComfyUI_EmAySee_CustomNodes

Restart ComfyUI (or search ComfyUI_EmAySee_CustomNodes in ComfyUI Manager). There's no requirements.txt and nothing to download - this is pure math on tensor shapes, so ComfyUI's bundled Python is all it needs.

Where people trip up

  • The reference image drives everything. This node doesn't invent an aspect ratio - it copies the one on the image you plug in. Feed it a square you want matching, feed it a 9:16 portrait and it preserves that. If the output looks "wrong," check what image is actually connected.
  • Only the width is rounded. If you type a height that isn't a multiple of 64, the node returns it as-is. The UI's step and dropdown usually prevent this, but nothing in the code backstops it - keep heights on the grid yourself.
  • The width can run away from you. Matching a very wide panorama at 1024 height gives you a width well past what most checkpoints are happy generating. The node won't clamp; if you need SDXL-sane dimensions, keep the reference ratio modest or cap the result downstream.
  • Batch gotcha. It reads only the first image of the batch. If you feed it a batch of mixed-aspect images, the ratio is whatever the first frame is.

Is it a must-have? No - plenty of packs ship aspect-ratio utilities, and ComfyUI's own empty-latent sizing does most of this by hand. But if you're doing img2img or ControlNet passes where the output must match a source image's framing, this is the node that makes "same shape, VAE-safe, zero mental math" a one-wire operation.

CategoryEmAySee/Utils

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
output_heightINT512

Outputs (2)

NameTypeDescription
output_widthINT
output_heightINT