Gemini Outpaint
Extend the canvas beyond its edges — Gemini outpainting that understands the scene
- image
- image
You have a 1:1 portrait and you need a 16:9 hero shot. Or a wide establishing shot that stops three pixels past the subject. Local outpainting has always been the awkward cousin of inpainting - the diffusion model has to invent an entire new region with only the image edge as a hint, and it shows. This node hands the job to a Gemini image model instead, which means the extension is reasoned: it reads the scene - the lighting, the perspective, the style - and extends it in the direction you choose with a prompt telling it what's out there.
It's the node you reach for when the empty canvas matters more than a seamless texture patch: turning a square asset into a different aspect ratio, adding context around a subject, or fixing a badly-cropped composition before it goes into a video workflow. The output drops back into the graph as a normal image, ready for an upscaler or an img2vid pass.
How it works
Like the Inpaint node, this goes through generate_content with the image sent as a JPEG part and an instruction built from your choices - literally "Extend this image to the right. Fill the new area with: …". The model gets a system instruction to extend seamlessly while keeping style and context consistent, and the returned image stream is decoded back into a ComfyUI IMAGE tensor.
The mechanism detail that matters: outpainting direction is explicit, not inferred. You pick right, left, up, down, or all, and the model builds the new region in exactly that direction. all is your 1:1-to-wider trick, adding canvas on every side at once.
Inputs and outputs that matter
image- the source you're extending.direction- which edge(s) to grow. The default isright, and the order you compose prompts and crops around it is the one thing that varies per workflow.prompt- what lives in the new area. "A sunlit beach continuing to the horizon" beats nothing - an empty prompt means the model free-associates the extension.aspect_ratio- the interesting control. DefaultAUTOlets the model decide; or lock it to a target like16:9or9:16and the output comes back composed to that ratio. That's the whole "reframe this asset" use case in one dropdown.model- the same image-capable trio as Inpaint (gemini-3.1-flash-image-previewby default, Pro available for quality).
One output: image (IMAGE).
How to install it
Same pack-level install as everything in this collection:
cd ComfyUI/custom_nodes
git clone https://github.com/IxMxAMAR/ComfyUI-API-Toolkit
cd ComfyUI-API-Toolkit
pip install -r requirements.txt
or "API Toolkit" from ComfyUI Manager. Gemini needs google-genai>=0.8.0 and a key (GEMINI_API_KEY env var or the node field). Nothing to download.
Common issues
The classic failure is a mismatched extension - the model invents content that doesn't match the lighting or perspective of the original. That's mostly a prompt problem: describe the extension in terms of the existing scene, and reach for the Pro model when Flash gets sloppy. If the result looks like a paste-job, aspect_ratio set to a target can actually help, because the model is composing the whole canvas to a known shape instead of improvising.
And the usual API-node realities: every queue is a paid image call (the pack's IS_CHANGED override makes sure the node re-runs each time), and Google's content filter applies - a closed, moderated model refuses what it refuses, with no local workaround.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| api_key | STRING | Gemini API key. Leave blank to use GEMINI_API_KEY env var. | |
| model | COMBO | gemini-3.1-flash-image-preview | Image-capable Gemini model for outpainting. |
| custom_model | STRING | Override with a custom model ID. | |
| image | IMAGE | The source image to extend. | |
| direction | COMBO | right | Direction to extend the image. |
| prompt | STRING | Describe what should appear in the extended area. | |
| system_instructionopt | STRING | System instruction for the outpainting model. | |
| aspect_ratioopt | COMBO | AUTO | Target aspect ratio after outpainting. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |