Image_pad_adjust
Pad an image to the size your model wants, without losing the original
- image
- mask
- image
- mask
- stitch
Plenty of models and workflows want a specific canvas - divisible by 8 or 64, a perfect square, an exact target resolution - and your source image is almost never already that shape. You could crop to fit and lose part of the image, or you could pad. Image_pad_adjust pads, and it's built as one half of a pair with Image_pad_adjust_restore specifically so the padding doesn't have to be a one-way trip: it hands back a token that lets you strip the padding back off later and land exactly where you started.
This is the same idea behind the crop-and-stitch pattern that became the default for masked inpainting in 2026 - do your generation on a modified canvas, then mechanically restore everything outside the region you actually changed - just applied to padding-to-fit instead of cropping-to-a-region.
How it works
top/bottom/left/right set explicit padding on each side (they can go negative, effectively pre-cropping that side instead). bg_color fills the new area, smoothness feathers the pad-mask edge, and divisible_by (default 2) rounds the final canvas up so its dimensions divide evenly - the usual thing models with a VAE downsample factor need. auto_pad overrides the manual numbers with one of three modes: None (use the explicit top/bottom/left/right values as-is), auto_square (pad the shorter side to match the longer one), or target_WxH (pad to an exact target_W × target_H, positioned per pad_position - a nine-way anchor grid from left-top through right-bottom).
The inputs and outputs that matter
auto_pad- the one decision that changes everything else.target_WxHwithtarget_W/target_Hset is the right choice if you know your workflow's exact required size;auto_squareif you just want a square canvas without doing the arithmetic; leave it atNoneif the four directional numbers are your source of truth.top/bottom/left/right(default 0 each) - manual padding per side.bg_color(default"black") - fill for the new area.divisible_by(default 2) - rounds the output up to a multiple of this value.- Output:
image,mask(the pad region - feed to your sampler like any outpaint mask), andstitch(typeSTITCH4- hand this toImage_pad_adjust_restoreonce you're done generating on the padded canvas).
How to install it
Via ComfyUI Manager: search ComfyUI-Apt_Preset, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git
Windows: install.bat. Linux/Mac: pip install -r ComfyUI-Apt_Preset/requirements.txt in your venv. Restart. Nothing to download for canvas math - the pack's broader dependencies belong to other parts of this ~300-star, actively maintained pack.
Common issues & troubleshooting
Output canvas is bigger than expected. divisible_by rounds the final size up beyond what top/bottom/left/right alone would produce, to satisfy the divisibility constraint - check the actual output dimensions rather than assuming they equal source size plus your four numbers exactly.
Lost the ability to restore afterward. Don't drop the stitch output between here and Image_pad_adjust_restore - without it, restore has nothing to work from and you're back to compositing manually.
Padding trick for instruction-editing models. If you're outpainting with a model like Flux Klein rather than doing a classic masked inpaint, a flat, uncommon bg_color (not white or black - the model may read those as intentional) paired with a prompt asking it to "remove the padding and show what's behind it" is a real, circulating trick worth knowing this node enables directly.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| top | INT | 0-14096–14096 | — |
| bottom | INT | 0-14096–14096 | — |
| left | INT | 0-14096–14096 | — |
| right | INT | 0-14096–14096 | — |
| bg_color | COMBO | black | 6 options: white, black, red, green, blue, gray |
| smoothness | INT | 00–500 | — |
| divisible_by | INT | 21–512 | — |
| auto_pad | COMBO | None | 3 options: None, auto_square, target_WxH |
| pad_position | COMBO | mid-center | 9 options: left-top, mid-top, right-top, left-center, mid-center, right-center, +3 |
| target_W | INT | 5121–14096 | — |
| target_H | INT | 5121–14096 | — |
| pad_mask_remove | BOOLEAN | true | — |
| imageopt | IMAGE | — | |
| maskopt | MASK | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| stitch | STITCH4 | — |