ComfyUI Node

CropTo

The 'stop yelling about tensor sizes' node

By TeaCrab·Created 3 years ago·Updated 5 months ago· 5
CropTo
  • image_src
  • image_ref
  • IMAGE

Half of ComfyUI errors are dimension mismatches - one node outputs 896×1152, the next one quietly demands 1024×1024, and the queue dies with a wall of tensor math. CropTo is the author's answer to that: feed it a source image and a reference image, and it returns the source cropped to exactly the reference's width and height. Two inputs, one output, nothing to configure.

It's one of ten nodes in the small ComfyUI-TeaNodes pack by TeaCrab, MIT-licensed, sitting in the TeaNodes/Image menu. The README sums up the vibe: "Hate some of those nodes that complains about bad tensor dimensions for whatever reasons? Fear no longer."

How it works

Under the hood it's a single center_crop from torchvision. image_src is cropped around its center down to the spatial size of image_ref - no scaling, no distortion, no resampling that softens the image. The output is the same aspect ratio as the reference only because it is the reference's size now. That makes it the natural front-end for anything downstream that demands a fixed resolution: img2img chains, latents that need to match, or stacking images for comparison.

When you'd reach for it

  • img2img prep. Your input photo is 1536×2048, your generation size is 1024×1024. CropTo matches them so the sampler isn't silently re-encoding a different resolution.
  • Upscale or detail passes where a model gets cranky about odd dimensions.
  • Aligning a source to a reference so two branches of a graph finally agree.

The one thing to know before wiring it up

It crops from the center, which means it throws away the edges, not the middle. If your subject isn't centered, you'll crop off the interesting part. And if image_ref is larger than image_src, center_crop doesn't upscale to meet it - it zero-pads, so you get black bars instead of a bigger image. That's the trap: CropTo shrinks cleanly but never grows. If you need the reference bigger than the source, resize first.

Inputs: image_src (what gets cropped) and image_ref (the size template). Output: a single IMAGE. That's the whole interface.

Installing it

It ships with the rest of TeaNodes. ComfyUI Manager → search ComfyUI-TeaNodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/TeaCrab/ComfyUI-TeaNodes

then restart ComfyUI. No models, no heavy installs - the pack's only declared dependency is the author's regex_spm helper; kornia, used by a couple of the image nodes, already ships with ComfyUI core.

If you've spent an afternoon fighting dimension errors, you'll install this and quietly wonder why you didn't sooner. It's a dumb fix for a dumb recurring problem, and that's exactly what it should be.

CategoryTeaNodes/Image

Inputs (2)

NameTypeDefaultDescription
image_srcIMAGE
image_refIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE