jz Pad Calculator
Make Your Canvas Match What Gemini Actually Returns
- image
- pad_left
- pad_right
- pad_top
- pad_bottom
- target_w
- target_h
- aspect_ratio
- resolution
- fill_color
- padded_image
- outpaint_mask
The Gemini image API only generates at a fixed set of sizes. Ten aspect ratios, three resolutions, and the actual pixel dimensions aren't what you'd guess - "16:9 at 1K" is 1376×768, not 1280×720, and "21:9 at 4K" is a monstrous 6336×2688. If your padded canvas doesn't exactly equal the size the API returns, your composite lands misaligned and your outpaint falls apart. Gemini Pad Calculator exists so you never guess those numbers again.
In the wider workflow it's the first node after Load Image. It's the "Nano Banana Pad Calculator" from the README, and it answers the boring-but-critical question: how much do I pad this 827×1102 photo so Gemini can extend it, and what size does the API actually return?
How it works
It ships the API's dimension table in code - ten aspect ratios (1:1, 5:4, 4:5, 4:3, 3:4, 3:2, 2:3, 16:9, 9:16, 21:9) by three resolutions (1K / 2K / 4K). Given your image and (optionally) a target, it finds the best entry and computes centered padding. Three modes decide what "best" means:
- superior (default) - the smallest supported size that fully contains your image. That's what you want for outpainting: pad, never crop.
- inferior - the largest size that fits inside your image. This one crops (pads come out negative), so it's for resize-to-fit, not outpaint.
- closest - nearest by area, which can go either way.
With both aspect_ratio and resolution left on "auto", it picks the smallest containing size across the whole table - which is the right move for a first pass. The fill_mode decides what color the padding gets: edge_average (default) blends in the mean color of the outer 10px of your image, while unique picks a color guaranteed absent from the image (magenta first). Choose unique when you're using the pack's GeminiFillSeamRepair downstream - a fill color that can't appear naturally in the scene is how seam repair distinguishes "leftover pad" from "actual image content."
The outputs that matter
Eleven outputs, but you'll use six.
- pad_left / pad_right / pad_top / pad_bottom - wire into GeminiComposite. They're the offsets for pasting your original back.
- padded_image - the canvas ready to send. Feed it to GeminiImageGenerate as the input image.
- outpaint_mask - a MASK, 1.0 where the fill should happen. Feed it to GeminiFillSeamRepair (and convert to an IMAGE if your graph wants to send it to the generate node as the mask image).
- aspect_ratio and resolution - the resolved values (strings, not numbers). Wire these into GeminiImageGenerate so the API call returns exactly the size you padded to. This is the output pair that prevents the misalignment trap.
- fill_color - a solid IMAGE of the fill color, for GeminiFillSeamRepair.
- target_w / target_h - handy sanity-check numbers before you fire an API call.
Install
No model downloads, no API key needed for this node itself. The pack's only real dependency trap is scipy (there's no requirements.txt, and the pack imports scipy at load time - if it's missing, none of the nodes appear):
# ComfyUI Manager → search "ComfyUI-Outpainting-Gemini", or:
cd ComfyUI/custom_nodes
git clone https://github.com/jzhang-POP/ComfyUI-Outpainting-Gemini
source ../venv/bin/activate && pip install scipy # if not already installed
Restart ComfyUI. (The README's clone URL is a YOUR_USERNAME/Vermeer-Gemini.git placeholder - ignore it, use the one above.)
Troubleshooting
- Error saying your image exceeds all supported sizes - it's too big for the table (max is 6336×2688 at 21:9/4K or 3072×5504 at 9:16/4K). Downscale first, or you'll never get a pad value.
- It returns crops when you wanted pads - you're in
inferiormode. Switch back tosuperior. - The outpaint comes back the wrong size - you didn't wire the resolved
aspect_ratio/resolutionoutputs through, so the API call and the padding disagreed.
For a feature that's essentially a lookup table, this node is quietly the one that keeps the whole Gemini outpainting workflow honest. Wire it right once and the rest of the graph just works.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| aspect_ratio | COMBO | auto | 11 options: auto, 1:1, 5:4, 4:5, 4:3, 3:4, +5 |
| resolution | COMBO | auto | 4 options: auto, 1K, 2K, 4K |
| mode | COMBO | superior | 3 options: superior, inferior, closest |
| fill_mode | COMBO | edge_average | 2 options: edge_average, unique |
Outputs (11)
| Name | Type | Description |
|---|---|---|
| pad_left | INT | — |
| pad_right | INT | — |
| pad_top | INT | — |
| pad_bottom | INT | — |
| target_w | INT | — |
| target_h | INT | — |
| aspect_ratio | STRING | — |
| resolution | STRING | — |
| fill_color | IMAGE | — |
| padded_image | IMAGE | — |
| outpaint_mask | MASK | — |