Resize, Crop or Fit
Land any image exactly on your latent's dimensions
- image
- latent
- IMAGE
The img2img entry point is picky: the image you feed and the latent being sampled have to agree on dimensions, and they rarely do on their own. Resize, Crop or Fit is the honest fix - it takes your image and a latent, and brings the image to the latent's exact pixel size (latent dims times 8) with one of three strategies: stretch it, crop it, or letterbox it.
It's from comfyui_davcha, the "personal QoL and experimental nodes" pack. This node is the resize half of PadAndResize without the padding - if you don't need to extend the canvas, this is the leaner tool.
How it works
The mode input is the whole decision:
- resize - stretches the image to the latent's dimensions with nearest-exact interpolation. Fast, exact fit, but distorts unless the aspect ratios already match.
- crop - scales up by the larger ratio, then center-crops. Fills the entire frame with no bars; you lose the edges.
- fit - scales by the smaller ratio, then letterboxes with gray fill and a soft feathered alpha edge. Nothing is lost; you gain bars.
Under the hood it resizes with InterpolationMode.NEAREST_EXACT (no blurry half-pixel smearing) and, in fit mode, builds a distance-transform alpha ramp so the letterbox edges feather instead of snapping.
Inputs: image (IMAGE), latent (LATENT), mode (the three-way enum). Output: IMAGE (RGBA when fit letterboxes).
When you'd reach for it
- Before any img2img pass - reconcile an odd-sized source with the latent your sampler expects.
- Native-resolution control - SD-family models degrade off their native resolutions; resize the input to a model-native size before sampling rather than letting the sampler guess.
- Hires-fix alignment - after upscaling a latent, bring the reference image back in line with it.
Installing it
# ComfyUI Manager → Install Custom Nodes → search "comfyui_davcha" → Install → Restart
# or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/dchatel/comfyui_davcha
cd comfyui_davcha
pip install -r requirements.txt
Pack-level catch as always: nodes.py imports llama_cpp and cv2 at module load though requirements.txt only lists webp and rapidfuzz. Pack not showing up? pip install llama-cpp-python opencv-python and restart.
Where people get burned: crop deletes pixels, so if your subject reaches the frame edges, crop will chop it - check before committing. And fit's gray bars are constant-fill with a fixed feather; if you need a specific fill color or want to pad the canvas rather than just resize onto it, that's PercentPadding or PadAndResize in the same pack. For everything else, this is the one to reach for.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| latent | LATENT | — | |
| mode | COMBO | 3 options: resize, crop, fit |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |