Nodes/ComfyUI-ImageResolutionFixer/Image Resolution Fixer
ComfyUI Node

Image Resolution Fixer

Fix that \"tensor size mismatch\" without butchering your image

By ohmygoobness·Created 7 months ago·Updated 28 days ago· 0
Image Resolution Fixer
  • image
  • image
  • width
  • height
fitsmart_fill
method
round_to_multiple16

You know the error. You load a reference image, hook it into an img2img or video workflow, and the run dies with some variation of "expanded size of the tensor must match existing size" because your 1023×767 image isn't divisible by what the model's VAE demands. The Image Resolution Fixer is a one-node answer to exactly that: it nudges your image to the nearest compatible resolution with almost no visible change.

The name undersells it. This isn't a resizer you reach for when you want a smaller or bigger image - it's the node you drop in front of anything finicky so the math works. Every model has a native resolution and a divisibility requirement, because its VAE downsamples the image 8× per side into latent space before diffusion ever runs (that's why Flux, SDXL, and most of the recent video models want dimensions divisible by 8, 16, or 64). Feed an odd dimension into that latent space and the tensors don't line up. This node rounds your pixels up to a clean multiple, which is the same thing people hand-roll with math nodes - just with better edge handling.

How it actually works

The core is one math.ceil per dimension: it rounds your width and height up to the nearest multiple you pick, nothing more. A 450×603 image with round_to_multiple: 16 becomes 464×608 - a handful of pixels, not a resizing. One honest gotcha: the README's SDXL example shows 450×603 → 448×640, but the shipped code always rounds up, so you'll get 512×640 in practice. Don't be surprised when your "fix" adds pixels rather than removing them.

The interesting part is fit, and specifically smart_fill, the default. Every other option is standard: fill stretches to exact dimensions, letterbox pads with black bars, crop center-crops. smart_fill instead resizes the image to fit within the target (preserving aspect ratio), then pads the remaining few pixels using OpenCV's BORDER_REFLECT_101 - it mirrors the image content at the edges, so the seam looks like a texture continuation instead of a smeared strip or a bar. For the 1–63 pixels this node typically adds, it's genuinely the best-looking choice, and it's cheap. All the tensor gymnastics happen in the method dropdown too: lanczos for quality, bilinear when you want speed.

The inputs that matter

Three of the four inputs are enums, so there's not much to get wrong:

  • round_to_multiple - the one you actually care about. Defaults to 16. Use 8 for most SD 1.5/2.1 models, 64 for SDXL and SVD, 16–32 for Wan, Hunyuan, and LTX-Video. 14 and 28 exist specifically for SVD's odd frame requirements. Smaller multiples mean fewer added pixels.
  • fit - default smart_fill is right 90% of the time. Switch to letterbox only if you want honest bars.
  • method - leave on lanczos.

Outputs are image (the fixed tensor), plus width and height as plain ints - handy if you want to wire the final size into a text or math node downstream instead of recomputing it.

Installing it

Through ComfyUI Manager, search "Image Resolution Fixer" and hit install. Or the manual way:

cd ComfyUI/custom_nodes
git clone https://github.com/ohmygoobness/ComfyUI-ImageResolutionFixer

then restart ComfyUI. The only real dependency is opencv-python - and only for the smart_fill path; if you stick to fill, letterbox, or crop you don't need it at all. Most ComfyUI installs already ship cv2. If the node loads but throws No module named 'cv2', run pip install opencv-python (or python_embeded\python.exe -m pip install opencv-python on the portable Windows build). No models to download, no weights, nothing heavy - this is one file doing the work.

When it bites

If the node isn't in your node list, it's usually a folder-naming or restart issue - close ComfyUI completely, not just the workflow. And if you still get a tensor mismatch after running it, you picked too small a multiple; jump to 64 and the error almost always goes away. The common failure I see people hit in the wild: dropping this on the frame dimension of a video thinking it fixes frame-count requirements. It only fixes width/height, so pair it with whatever handles the temporal side for your model. For image and img2img work, though, this is the smallest, least invasive fix in the box.

Categoryimage/transform

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
fitCOMBOsmart_fill4 options: smart_fill, letterbox, crop, fill
methodCOMBO6 options: lanczos, bicubic, hamming, bilinear, box, nearest
round_to_multipleCOMBO1611 options: 2, 4, 8, 14, 16, 28, +5

Outputs (3)

NameTypeDescription
imageIMAGE
widthINT
heightINT