TenguPad v0.4
Letterboxing that keeps its color — and hands you a mask
- image
- IMAGE
- mask
- Width
- Height
TenguPad is a "fit an image into a canvas" node: resize to a target width and height while keeping the aspect ratio, then either pad the leftover space with a solid color or crop the overflow. Yes, core ComfyUI already ships Image Resize, and yes, this is strictly more opinionated than that. The difference is everything wrapped around the resize - true 0–255 RGB padding color, nine position choices for pad and crop, a content scale knob, and a mask output that marks exactly where your image ended up.
You reach for this when your source doesn't match your target ratio. Models train at native resolutions - SDXL at 1024², Flux in a band around 1024, video models at their own fixed frames - and the KB's oldest piece of advice is that you never want to stretch pixels into a ratio the model never saw. If you're pushing a 1:1 render into a 16:9 canvas for a video workflow or a composited scene, you either pad it or crop it. TenguPad does both, cleanly, without you hand-building an Empty Latent and three composite nodes.
How it works
The core is one aspect-ratio-preserving resize via comfy.utils.common_upscale, then a copy of the scaled image into a solid-color canvas of your target size. Three aspect_ratio_mode options decide the rest:
- pad - fit the whole image inside the canvas, fill the leftover bars with your color.
- crop - scale up until the image covers the canvas, then cut the overflow.
- stretch - ignore the ratio and squeeze to fit. Usually a mistake; it exists because sometimes you just need the dims.
content_scale is the neat trick: it scales the image content inside the padded space after the fit. Below 1.0 shrinks the picture and adds extra padding; above 1.0 enlarges it (and in pad mode, the author warns, can start cropping). padding_position and crop_position pick where content sits - center, top-left, bottom-right, and friends - which is how you bias a crop to keep someone's face instead of their forehead.
Padding color is real RGB, not the lazy "black or white" you usually get. Nine color_preset options (white, black, gray, RGB primaries, cyan, magenta) plus a custom mode with pad_r/pad_g/pad_b sliders, 0–255. The default preset is green, which reads as a quiet nod to chroma-key: pad the canvas green, feed it somewhere that keys on green, done. interpolation defaults to lanczos - switch to area for heavy downscales or nearest-exact for pixel art.
The outputs nobody mentions
Besides the IMAGE, TenguPad emits a mask (1.0 over the image region, 0.0 over padding) and Width/Height ints. That mask is the sleeper feature. Wire it into an inpaint pipeline and you can regenerate only the padded bars - true outpaint-style canvas expansion without touching the original pixels, which is exactly the discipline the KB's inpainting section pushes. feather_pixels and mask_dilation (0–100, negative erodes) soften or grow that mask's edges; note they only affect the mask, never the image itself. The W/H outputs chain straight into an Empty Latent, which is how you pad in pixel space and still sample at the exact dims you planned.
Install
No model files, no requirements.txt, no heavy deps - it's pure torch + OpenCV, both already in any ComfyUI install. Through Manager, search "TenguPad"; or:
cd ComfyUI/custom_nodes
git clone https://github.com/tekijiyuu/TenguPad
Restart ComfyUI. One caveat: the code is written against ComfyUI's newer comfy_api.latest SDK-style API, so it wants a current ComfyUI. If the node won't register on a stale install, update ComfyUI before blaming the pack.
Where people get burned
The preset wins. If you pick green, the code overwrites your pad_r/g/b sliders no matter what you set - pick custom to drive colors manually. And remember content_scale > 1.0 in pad mode can bite you by cropping, which is the opposite of why you chose pad. It's a small pack with a small surface - the README is one line - but for "letterbox without the jank," it does the job.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| target_width | INT | 5121–8192 | — |
| target_height | INT | 5121–8192 | — |
| aspect_ratio_mode | COMBO | pad | • pad: Preserve aspect ratio with padding • crop: Preserve aspect ratio by cropping overflow • stretch: Ignore aspect ratio, stretch to fit |
| content_scale | FLOAT | 1.000.01–2 | Scale image content within padded space: • < 1.0: Make image smaller inside padding (adds extra padding) • = 1.0: Normal padding behavior • > 1.0: Enlarge content (may cause cropping in pad mode) |
| padding_position | COMBO | center | Position of content within padded canvas (used in 'pad' mode) |
| crop_position | COMBO | center | Which part of the image to preserve when cropping (used in 'crop' mode) |
| interpolation | COMBO | lanczos | 5 options: lanczos, bicubic, bilinear, area, nearest-exact |
| feather_pixels | INT | 00–100 | Number of pixels to feather the mask edges for smooth transitions |
| mask_dilation | INT | 0-100–100 | Positive values dilate (expand) the mask, negative values erode (shrink) the mask |
| color_preset | COMBO | green | Quickly set RGB values. Select 'custom' for manual control. |
| pad_r | INT | 2550–255 | — |
| pad_g | INT | 2550–255 | — |
| pad_b | INT | 2550–255 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| mask | MASK | — |
| Width | INT | Final output image width in pixels |
| Height | INT | Final output image height in pixels |