PadAndResize
Extend an image by percent, then force it onto your latent's size
- image
- latent
- IMAGE
The classic img2img chore: your image is one aspect ratio, your latent is another, and the sampler is about to complain. PadAndResize solves both halves in one node - pad the image out by a percentage of its own size on each side, then resize, crop or fit it to exactly match a latent's pixel dimensions (latent dims times 8, the VAE's downscale factor). Out comes an RGBA image that slots into your latent without a shape mismatch.
It's from comfyui_davcha, the "personal QoL and experimental nodes" pack, and it's the heavyweight version of the pack's ResizeCropFit - same resize logic, plus padding.
How it works
The padding step takes left, top, right, bottom as FLOAT percentages of the image's own width and height (left/right of width, top/bottom of height) and pads with constant fill. It builds a mask for the padded area and appends it as an alpha channel if the image doesn't have one (or multiplies the existing alpha), so the padded borders are transparent rather than filled with visual noise.
Then the resize step matches the latent: resize stretches to the latent's dimensions with nearest-exact interpolation (distorts), crop scales up by the larger ratio and center-crops (fills the frame, cuts edges), and fit scales by the smaller ratio and letterboxes with gray fill and a feathered alpha edge (keeps everything, adds bars).
Inputs: image (IMAGE), latent (LATENT), mode (resize/crop/fit), and the four padding floats. Output: IMAGE (RGBA when padding is applied).
When you'd reach for it
- Outpainting canvas prep - pad the image to a wider aspect ratio with transparent borders, encode, and let the sampler fill the gap.
- Aspect-ratio reconciliation - force an odd-sized source onto an existing latent without distortion (use
fit). - Framing for img2img - add a border before a regeneration pass so the model doesn't crop your composition.
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: nodes.py imports llama_cpp and cv2 at module load while requirements.txt only lists webp and rapidfuzz. Pack missing from your menu? pip install llama-cpp-python opencv-python and restart.
Where people get burned: crop genuinely removes pixels - check that your subject isn't near the edges before picking it. And remember the latent drives the math here; feed it a latent whose resolution doesn't match what you intend to sample at and the whole alignment is off by that factor. If you just want to extend a canvas with soft edges and don't need to match a latent yet, the same pack's PercentPadding is the lighter option.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| latent | LATENT | — | |
| mode | COMBO | 3 options: resize, crop, fit | |
| left | FLOAT | 0.00 | — |
| top | FLOAT | 0.00 | — |
| right | FLOAT | 0.00 | — |
| bottom | FLOAT | 0.00 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |