Nodes/ComfyUI-K3NKImageGrab/K3NK Image Overlay
ComfyUI Node

K3NK Image Overlay

A Faster Image Overlay for Big Batches (Drop-In for TSC's, Without the PIL Detour)

By K3NK3·Created 9 months ago·Updated 2 months ago· 8
K3NK Image Overlay
  • base_image
  • overlay_image
  • optional_mask
  • IMAGE
overlay_resize
resize_method
rescale_factor1.00
width512
height512
x_offset0
y_offset0
rotation0
opacity0.0

Want to stamp a logo on every frame of a video batch, or composite a watermark over a grid of images, without your VRAM spiking every time? K3NK Image Overlay is a compositing node that does the usual overlay stuff - position, scale, rotate, fade, mask - but does it entirely in tensor ops. The author's framing is the honest pitch: it's functionally identical to TSC Image Overlay from efficiency-nodes-comfyui, minus the PIL round-trips that hammer peak memory on large batches.

For a single image, either node is fine. For a 100-frame video batch or a big grid, staying in tensor land matters - you stop converting to PIL and back at every frame, and peak RAM stays flat instead of climbing. That's the whole reason to reach for this one.

How it works

The mechanism is straightforward alpha compositing done with PyTorch: resize the overlay (via ComfyUI's common_upscale), build an alpha channel from the mask or a solid one, optionally rotate both overlay and alpha with an affine grid sample, then composite frame by frame as base × (1-α) + overlay × α. Because the heavy lifting is tensor ops, batch size is handled cleanly - it loops over the batch dimension but never round-trips through PIL.

Two semantics will trip you up if you skim past them, because both are inverted from what you'd guess:

  • opacity - 0 means fully opaque (overlay fully visible), 100 means invisible. It's a "how much to remove" knob, not a "how much to show" knob.
  • optional_mask - white = transparent, black = opaque. Again flipped from the usual "white reveals" convention.

The README documents both, and the source confirms it, but it's the classic "why is my logo invisible?" moment. Default opacity is 0, so out of the box the overlay is fully visible - good.

The inputs that matter

  • base_image / overlay_image - the background batch and the thing stamped on top.
  • overlay_resize - None, Fit (scale to fit the base), Resize by rescale_factor, or Resize to width & height (the enum's "heigth" typo is upstream's, not yours).
  • resize_method - nearest-exact, bilinear, or area.
  • x_offset / y_offset - position. rotation - degrees, −180 to 180. opacity - see the warning above.

Output is a single IMAGE - the composited batch, same batch size as base_image. If the overlay lands entirely outside the base, it returns the base unchanged rather than erroring, which is friendlier than you'd expect from most nodes.

Installing it

Part of the K3NK pack. ComfyUI Manager → search ComfyUI-K3NKImageGrab, or:

cd ComfyUI/custom_nodes
git clone https://github.com/K3NK3/ComfyUI-K3NKImageGrab

Restart ComfyUI. Pure torch + ComfyUI's own utils - nothing extra to install.

Where people get burned

Beyond the inverted opacity/mask, the practical trap is "Fit" combined with a mask. The mask is resized to match the overlay, so if your mask was drawn at a different aspect ratio than the overlay, it stretches to fit - check it. And if you're swapping this in for TSC's node inside an existing workflow, the drop-in claim is mostly true, but the enum labels differ slightly, so re-pick the resize mode after the swap. Behavior otherwise matches, and your batch workflows get noticeably lighter on memory.

CategoryK3NK/image

Inputs (12)

NameTypeDefaultDescription
base_imageIMAGE
overlay_imageIMAGE
overlay_resizeCOMBO4 options: None, Fit, Resize by rescale_factor, Resize to width & heigth
resize_methodCOMBO3 options: nearest-exact, bilinear, area
rescale_factorFLOAT1.000.01–16
widthINT5120–48000
heightINT5120–48000
x_offsetINT0-48000–48000
y_offsetINT0-48000–48000
rotationINT0-180–180
opacityFLOAT0.00–100
optional_maskoptMASK

Outputs (1)

NameTypeDescription
IMAGEIMAGE