Single-file Gemini image generation CLI with batch and grid output.
  • Python 62.3%
  • HTML 37.7%
Find a file
2026-03-01 12:46:09 +01:00
.gitignore chore(prompt): update prompt text and ignore prompt files 2026-03-01 11:48:42 +01:00
cafe-image.prompt script 2025-12-01 13:01:40 +01:00
img.py feat(cli): allow configuring image size and aspect ratio for generation 2026-03-01 12:42:55 +01:00
prompt chore(prompt): update prompt text and ignore prompt files 2026-03-01 11:48:42 +01:00
README.md docs: add usage guide for nano banana image cli 2026-03-01 12:46:09 +01:00
viewer.html feat(viewer): add auto-refreshing grid to inspect generated images 2025-12-08 22:17:14 +01:00

Nano Banana 2

Single-file CLI for generating images with Google's Gemini 3.1 Flash model. Supports text-to-image, image-to-image, batch generation with parallel API calls, and automatic grid composition.

Setup

Requires Python 3.13+ and a Gemini API key.

export GEMINI_API_KEY="your-key-here"

Dependencies (requests, pillow) are declared inline via PEP 723uv run handles them automatically.

Usage

# text-to-image
uv run img.py -p "a cat wearing sunglasses"

# prompt from file
uv run img.py -f my-prompt.prompt -o portrait.png

# image-to-image with reference photos
uv run img.py -p "oil painting style" -i photo.jpg -o painting.png

# multiple reference images (shell glob)
uv run img.py -p "blend these" -i in_photos/* -o blended.png

# batch: generate 4 variations in parallel, get a grid
uv run img.py -p "sunset landscape" -n 4 -s 2K -a 16:9 -o sunset.png
# → sunset-1.png, sunset-2.png, sunset-3.png, sunset-4.png, sunset.png (grid)

Options

Flag Description Default
-p, --prompt Prompt text
-f, --prompt-file Read prompt from file
-i, --input Reference image(s), repeatable none
-o, --out Output filename output.png
-n, --num-images Number of images to generate in parallel 1
-s, --size Resolution: 512px, 1K, 2K, 4K 1K
-a, --aspect-ratio Aspect ratio (e.g. 16:9, 3:2, 9:16) API default

Batch output

When -n is greater than 1, individual images are written as <name>-1.png, <name>-2.png, etc. A grid image combining all results is saved to the base output name. The grid uses shelf-packing at original resolution — no resizing or cropping.

Viewer

Open viewer.html in a browser to live-monitor generation progress. It auto-refreshes and displays output images in a grid.