Nodes/ComfyUI-Apt_Preset/Image_pad_adjust
ComfyUI Node

Image_pad_adjust

Pad an image to the size your model wants, without losing the original

By cardenluo·Created 2 years ago·Updated 17 days ago· 309
Image_pad_adjust
  • image
  • mask
  • image
  • mask
  • stitch
top0
bottom0
left0
right0
bg_colorblack
smoothness0
divisible_by2
auto_padNone
pad_positionmid-center
target_W512
target_H512
pad_mask_removetrue

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_WxH with target_W/target_H set is the right choice if you know your workflow's exact required size; auto_square if you just want a square canvas without doing the arithmetic; leave it at None if 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), and stitch (type STITCH4 - hand this to Image_pad_adjust_restore once 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.

CategoryApt_Preset/image

Inputs (14)

NameTypeDefaultDescription
topINT0-14096–14096
bottomINT0-14096–14096
leftINT0-14096–14096
rightINT0-14096–14096
bg_colorCOMBOblack6 options: white, black, red, green, blue, gray
smoothnessINT00–500
divisible_byINT21–512
auto_padCOMBONone3 options: None, auto_square, target_WxH
pad_positionCOMBOmid-center9 options: left-top, mid-top, right-top, left-center, mid-center, right-center, +3
target_WINT5121–14096
target_HINT5121–14096
pad_mask_removeBOOLEANtrue
imageoptIMAGE
maskoptMASK

Outputs (3)

NameTypeDescription
imageIMAGE
maskMASK
stitchSTITCH4