ComfyUI Node

PadBlackBorder

The Boring Node DiffusionLight Can't Run Without

By DiffusionLight·Created about a year ago·Updated about a year ago· 23
PadBlackBorder
  • image
  • IMAGE
height1024
width1024

Look at the DiffusionLight reference workflow and you'll see this node sitting right after LoadImage, doing the least glamorous job in the graph: making your photo fit a square. The inpainting pass that reconstructs the chrome ball runs at 1024×1024 - SDXL's native size - and your camera photo is almost certainly not square. If you just resize it to a square you squash the scene, the ball becomes an ellipse, and the depth map the ControlNet relies on quietly lies to the model. PadBlackBorder exists so that never happens.

The approach is the honest one: resize to fit inside the target while keeping aspect ratio, then center the result on a black canvas and letterbox the rest. The ball stays round, the geometry stays true, and the empty space becomes pure black - which for this pipeline is exactly right, since black contributes no light.

How it works

The node computes a single scale factor from the two axes - min(target_height / H, target_width / W) - so nothing gets distorted. It resizes with bilinear interpolation, then places the result dead-center on a black tensor of exactly height × width, with the leftover space split evenly top/bottom and left/right. Output is always exactly the size you asked for.

The inputs that matter

  • image - any IMAGE in the standard [B, H, W, 3] ComfyUI format.
  • height (default 1024) and width (default 1024) - the target canvas. The workflow uses 1024×1024 because that's what the depth preprocessor and SDXL sampling expect. Range 1 to 8192 each.

The single output is an IMAGE of exactly height × width, letterboxed. In the workflow it fans out to the MiDaS depth preprocessor and VAEEncodeForInpaint, so the depth map and the inpaint region share the same canvas.

Installing it

Part of the DiffusionLight-ComfyUI pack - ComfyUI Manager → search "DiffusionLight", or git clone https://github.com/DiffusionLight/DiffusionLight-ComfyUI into ComfyUI/custom_nodes, then restart. No extra dependencies: torch only. The full pipeline still needs comfyui_controlnet_aux and the model files in the README (SDXL checkpoint, SDXL depth ControlNet, Exposure + Turbo LoRAs), but this node is self-contained - you could lift it out for any workflow that wants a "fit inside a fixed canvas" utility.

Gotchas

  • Black fill only. If you want a colored or blurred border for a different pipeline, this isn't the node - it's strictly zero-fill. That's a feature here (black = no light), a limitation elsewhere.
  • It doesn't crop. An ultra-wide photo gets heavy bars; if you'd rather lose the edges than the resolution, crop first.
  • If your source is bigger than the target it downsamples - so feed it a reasonably-sized photo, not a 40MP original you'll want to keep detail in. The upscaling stage in the workflow handles final quality; this node just normalizes the canvas.
  • Keep height and width sane for your VRAM. 8192×8192 is legal, but every downstream node in the workflow will feel it.
Categorysd

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
heightINT10241–8192
widthINT10241–8192

Outputs (1)

NameTypeDescription
IMAGEIMAGE