Nodes/ComfyUI_Gayrat/Concat Images Logic
ComfyUI Node

Concat Images Logic

Jam 2–4 images into one frame for Flux Kontext

By gayratv·Created about a year ago·Updated about a year ago· 3
Concat Images Logic
  • image1
  • image2
  • image3
  • image4
  • IMAGE
background_color#000000

The reason this node exists is one very specific workflow: Flux Kontext. Kontext is BFL's instruction-editing model - you hand it a reference image plus a sentence, and it edits the frame. But it wants one image input, not several. If you're building a Kontext workflow where the context is "this character, this pose, this background," you need to fuse those references into a single composite first. That's this node's entire job: take two, three, or four images and glue them into one.

The README spells out the intent plainly: "concatenates 2 to 4 images into one for Flux Kontext," and notes the background color can come from a Color Input node (RMBG-style). It's a small, dumb, useful tool - no AI anywhere in it, which is the point.

How it works

It's plain PIL compositing. All input images get resized to the same canvas size - the max width and max height across the batch - so nothing is cropped, only padded against a background color. Then it lays them out:

  • 1 image: returned as-is.
  • 2 images: side by side, left then right.
  • 3 or 4 images: a 2×2 grid, row-major.

The layout choice is worth knowing: two images go in a row, but three already flip into a 2×2 grid with the third in the bottom-left. If you feed it images of wildly different aspect ratios, the padding makes the grid uniform but leaves dead space - set background_color (default #000000) to match, and it looks deliberate.

Inputs: image1 (required), then optional image2, image3, image4, and background_color as a hex string. One IMAGE output. Note the node always returns a single image with float("NaN") in its IS_CHANGED, so it re-runs every queue - that's intentional for a compositing node, and it means any change upstream propagates immediately.

Where it fits

The classic Kontext pattern: load your character reference, your pose reference, maybe a style image, concat them into one frame, and feed the result into the Kontext model's image input alongside your edit instruction. Because instruction-editing models re-emit the whole frame, you're not inpainting a masked region - you're giving the model a contact sheet of what matters and letting it work the whole canvas. This node is the "build the contact sheet" step. A couple of honest caveats: it pads rather than crops, so mixed aspect ratios leave letterbox bars (choose background_color accordingly), and it upscales small images to the largest in the batch, which can soften them. If you need clean tight crops instead, do that upstream before you concat.

Install

ComfyUI Manager: search ComfyUI_Gayrat. By hand:

cd ComfyUI/custom_nodes
git clone https://github.com/gayratv/ComfyUI_Gayrat
cd ComfyUI_Gayrat
pip install -r requirements.txt

Restart ComfyUI; it shows up under the image processing menu. It's from a small personal pack (gayratv's grab-bag of forks) with no real community presence, so treat the source as the documentation. No extra model downloads - just torch, Pillow and numpy, all of which ComfyUI already has.

Categoryimage processing

Inputs (5)

NameTypeDefaultDescription
image1IMAGE
image2optIMAGE
image3optIMAGE
image4optIMAGE
background_coloroptSTRING#000000

Outputs (1)

NameTypeDescription
IMAGEIMAGE