Pad to Resolution
Letterboxing for models that demand exact sizes
- image
- PADDED_IMAGE
- SCALED_WIDTH
- SCALED_HEIGHT
Some models are picky. Cloud image APIs want exact resolutions, regional workflows need a canvas at a fixed size, and img2img into a constrained latent space gets unhappy when your input is 1300×700 and the target wants 1024×1024. Pad to Resolution exists for exactly that moment: it takes any image, scales it to fit inside one of a list of target resolutions, and pads the leftover space with black or white. No cropping, no distortion - the whole image survives, just on a letterboxed canvas.
The clever part is how it picks the target. You give it a list of resolutions (one per line, 1024x1024 format) and it picks the one whose aspect ratio is closest to your source image, so you get the minimal amount of padding. Then it scales your image down to fit (LANCZOS, so quality holds), centers it, and fills the rest with your chosen pad color. If your image is already close to one of the resolutions, the padding is nearly invisible.
The inputs
- image - any
IMAGEtensor. - resolutions - a multiline string of
WxHtargets. Defaults to1024x1024,1536x1024,1024x1536, which covers portrait, landscape, and square in one go. Add or remove lines freely. - pad_color -
blackorwhite. No transparent option, which matters if you're prepping images for an API that wants transparency - you can't get it here.
Three outputs: PADDED_IMAGE (the result), plus SCALED_WIDTH and SCALED_HEIGHT - the size your image occupies inside the padding, before the letterbox. Those two are the whole point if you pair this with the pack's Crop from Padded node, which uses them to cut the padding back off and restore your original aspect ratio after the model has done its thing. Pad in, process, crop out.
Install
The standard pack routine - ComfyUI Manager → "Duanyll Nodepack" → install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Duanyll/duanyll_nodepack
cd duanyll_nodepack && pip install -r requirements.txt
The node only needs PIL/torch, but the pack's requirements list drags in OpenCV, kornia, insightface, matplotlib, and the Volcengine SDK.
Two things to know
First, malformed resolution lines are silently skipped - if you type 1024 1024 instead of 1024x1024, nothing breaks, it just ignores that line and moves on. Worth remembering when the output looks wrong. Second, the pad color decision isn't cosmetic for every downstream use: a white pad can bleed into an API edit's perception of the image edge, and black pads are usually the safer choice for latent-space work. And if all your resolutions produce a chosen target that's much larger than your source, you're paying for compute on dead pixels - keep the list tight and close to your real aspect ratios.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| resolutions | STRING | 1024x1024 1536x1024 1024x1536 | — |
| pad_color | COMBO | 2 options: black, white |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| PADDED_IMAGE | IMAGE | — |
| SCALED_WIDTH | INT | — |
| SCALED_HEIGHT | INT | — |