Nodes/GENKAI Nodes/Image Expand With Fill (genkai)
ComfyUI Node

Image Expand With Fill (genkai)

Change the aspect ratio without touching a single pixel of the original

By GENKAIx·Created about a month ago·Updated 21 days ago· 9
Image Expand With Fill (genkai)
  • image
  • image
◄left0►
◄right0►
◄top0►
◄bottom0►
◄stretch_filltrue►

The most common reason an image and a model disagree is shape. Your image is 832×1216, the video model wants 16:9. Your crop is 1000×1000 and the VAE wants a multiple of 8. Resizing and cropping both destroy something; padding destroys nothing.

Image Expand With Fill adds pixels on the left, right, top and bottom edges. The original never moves, never resizes, never gets re-encoded by a scaler. It's the most boring useful node in this pack.

How it works

It's numpy, not sampling, and the mechanism matters for knowing when it's the right tool.

With stretch_fill on (the default), the padding uses np.pad in edge mode: the outermost row and column of your image are repeated outward. A sky gradient extends as a smooth band; a high-contrast edge turns into visible streaks, because that's literally what copying pixels does.

With stretch_fill off, the node makes a larger canvas of zeros and pastes the image at (top, left). On an ordinary RGB image, zeros are black - so you get black bars, exactly like a letterbox.

Two implementation details worth knowing:

  • It converts through 8-bit. The tensor is clipped and cast to uint8, padded, then converted back to float. That's a quantisation round trip. Invisible for most work, but if you're chaining several padding/passthrough passes inside a latent pipeline, you're accumulating 8-bit steps.
  • All-zero padding is a passthrough. If every padding value is 0 the input is returned untouched, without the conversion. Nice guard, and it means you can leave the node in the graph unconditionally.

It works on IMAGE batches, applying the same padding to each frame - which is what makes it useful on frame batches going into a video model.

The inputs that matter

  • image - in.
  • left, right, top, bottom - integers, 0 to 8192 each. No ratio presets; you do the arithmetic.
  • stretch_fill - edge-stretch or black.
  • image (output) - the expanded image, back out as IMAGE.

What it's actually for

Four patterns, all of them grounded in how the rest of the stack behaves.

Aspect matching for video models. Pad a portrait still out to 16:9 and feed it as the conditioning frame. Black bars or stretched edges are less lossy than a crop that cuts off the subject.

Latent alignment. VAEs downsample by 8, and some samplers and ControlNet paths are happier on aligned dimensions. Padding a 1004-wide image to 1008 is cheaper than a resize that softens the whole picture.

Crop-and-stitch inpainting. Detailing and masked passes want margin around the region - the community rule of thumb is 32–64px - so the stitcher has pixels to blend into.

Colour-pad outpainting. The trick that circulates now needs no mask at all: pad with a flat colour and ask an instruction-edit model to replace it. This node only does black, so for red padding you want a companion node - but a black band works with models that will happily extend into it.

Honest limits

This is not outpainting. Black bars are just black, and edge stretch is a smear. Nothing here invents detail.

For latent-space work, stretched borders can act as a hard visual seam the model may or may not respect. If the model has to believe in the new area, use the tools built for it: masked crop-and-stitch outpainting, or a Fill-style instruction model trained on image-extend. This node just changes the canvas honestly and cheaply.

How to install it

cd ComfyUI/custom_nodes
git clone https://github.com/GENKAIx/Genkai-ComfyUI-Nodes

ComfyUI Manager → Genkai-ComfyUI-Nodes works the same way. Restart, Ctrl+F5. You'll find it under the plain GENKAI nodes category, alongside Folder Search - not under GENKAI/Media or GENKAI/Video. It needs nothing but torch and numpy, which every ComfyUI install already has.

Common issues

The output image looks identical to the input. Check the padding values before anything else - all-zero is a documented passthrough. The second suspect is an asymmetric fill you didn't notice: 0 left, 0 right, 200 top reads as "nothing happened" if you only look at the width.

Vertical streaks along the edges. That's edge-stretch on a high-contrast border, doing exactly what it does. Switch to stretch_fill off for black bars, or pad before the content that's causing it.

The subject is off-centre now. Padding applies to the sides you choose, so padding one side moves the subject within the frame rather than centring it. Split the delta between both sides if you want it centred.

Colours shifted slightly after a chain of passes. Likely accumulated 8-bit round trips from stacking image-space utility nodes. Keep them in the graph only where they're doing work.

CategoryGENKAI nodes

Inputs (6)

NameTypeDefaultDescription
imageIMAGE—
leftINT00–8192—
rightINT00–8192—
topINT00–8192—
bottomINT00–8192—
stretch_fillBOOLEANtrue—

Outputs (1)

NameTypeDescription
imageIMAGE—