Nodes/ComfyUI-LexTools/ImageAspectPadNode
ComfyUI Node

ImageAspectPadNode

The polite way to force an image into an aspect ratio

By SOELexicon·Created 3 years ago·Updated about a year ago· 33
ImageAspectPadNode
  • image
  • IMAGE
  • MASK
aspect_ratio1/1
invert_ratiofalse
feathering0
left_padding0
right_padding0
top_padding0
bottom_padding0
show_on_node0

Every diffusion model has native resolutions it likes, and your image is almost never one of them. You can stretch it - and get warped garbage. You can crop it - and lose half the composition. Or you can pad it, which is what ImageAspectPadNode does: it letterboxes your image to the aspect ratio you ask for, no distortion, nothing lost. The output even hands you a mask of the padding so you know exactly where the "fake" pixels are.

This is the node to reach for when you're pushing a non-standard image through a model that expects a square or a 16:9 frame. Pad a portrait to 1:1, run your img2img pass, crop the bars off afterward. Or flip it around: pad to a wider ratio and treat the padded strip as outpainting space - the MASK output tells you precisely which region is new, so an inpainting pass can fill the bars with actual content instead of leaving grey letterboxing.

How it works

It's pure pixel math, no model involved. You give it an image and a target ratio; it figures out which dimension to expand, and adds bars of the specified color (black by default) to the left/right or top/bottom until the image hits the ratio. Then it hands back both the padded image and a mask that marks the padding.

The inputs you'll actually touch:

  • image - the IMAGE to pad.
  • aspect_ratio - dropdown: 1/1, 4/3, 3/2, 16/9, 21/9. Pick the ratio you're targeting.
  • invert_ratio - true flips it. A 16:9 image padded to 16/9 gets side bars; with invert_ratio on, it pads the other axis instead. When the bars go on the wrong side, this is the switch.
  • feathering - blends the padding edge into the image with a soft gradient, so the seam between photo and padding isn't a hard line. A small value (say 8–32) makes an inpainted extension look far more natural.
  • left_padding / right_padding / top_padding / bottom_padding - manual overrides to force extra padding on a specific side, on top of the ratio math. Defaults to 0.

Outputs are IMAGE (the padded result) and MASK (1.0 where the padding is, 0.0 on the original). The mask is the useful half - wire it into SetLatentNoiseMask so a denoise pass only touches the bars.

The real workflow

The classic trick is "pad, inpaint the pad, crop". Pad your 3:2 photo to 1:1 with feathering on, use the MASK to constrain an inpainting pass to just the bars with a prompt like "extend the scene", then crop back to 3:2. You get a genuine outpainting with no warping and no retrained model. The community does this constantly for getting SDXL or Flux models to accept odd aspect ratios without the double-generation dance of the hires fix.

Install and notes

Part of ComfyUI-LexTools, so install the pack once: ComfyUI Manager → search "ComfyUI-LexTools", or git clone https://github.com/SOELexicon/ComfyUI-LexTools into custom_nodes and restart. No models to download - this one's just numpy and PIL.

One honest caveat: it pads, it doesn't resize. If the model you're feeding needs a specific resolution rather than a ratio, you'll still want a resize step after this. And the mask output assumes you want the padding filled with something - if you're just prepping an image for a fixed-ratio canvas, ignore the mask and feed the IMAGE straight on.

CategoryLexTools/ImageProcessing/AspectPad

Inputs (9)

NameTypeDefaultDescription
imageIMAGE
aspect_ratioCOMBO1/15 options: 1/1, 4/3, 3/2, 16/9, 21/9
invert_ratioCOMBOfalse2 options: true, false
featheringINT00–10240
left_paddingINT00–10240
right_paddingINT00–10240
top_paddingINT00–10240
bottom_paddingINT00–10240
show_on_nodeoptINT0

Outputs (2)

NameTypeDescription
IMAGEIMAGE
MASKMASK