# Nano Banana

> Generate images via the Gemini image API (nano banana). Use when you need to create a picture for a post, article, or any other image asset from a text prompt.

- Skill: `kexxx777xxx/nano-banana` (Agent Skill, multi-file: 5 files)
- Install (CLI): `npx skillmds@latest add kexxx777xxx/nano-banana`
- Raw SKILL.md: https://api.skillmd.com/api/skills/kexxx777xxx/nano-banana/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: kexxx777xxx (https://skillmd.com/u/kexxx777xxx)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/kexxx777xxx/nano-banana

---


# Nano Banana — image generation

Generate an image from a text prompt by running the script that lives next to this file:

    bash <skill-dir>/generate.sh "<image prompt>" "<output-path.png|.jpg>"

Example (skill installed into Hermes):

    bash ~/.hermes/skills/nano-banana/generate.sh "a cozy cabin in snowy mountains at dusk" ./post-cover.jpg

The script calls the Gemini API, extracts the base64 image from the response, decodes it,
and post-processes it according to the output extension and settings below.

## Behavior

- On success it prints `OK: <path> (<N> bytes)` and exits 0.
- If the API returns an error, the script prints the raw API response and exits 1.
  **Do not invent success** — report the error to the user as is.
- The output path defaults to `/tmp/nano_out.png` when omitted; the extension must be
  `.png`, `.jpg`, or `.jpeg`.

## Image size control

The Gemini API itself has no file-size or compression option for
`gemini-2.5-flash-image` — output is always a ~1024px-class PNG (~1-2 MB).
The API only accepts an aspect ratio; resolution presets (`imageSize`) exist
only on Gemini 3.x image models. Smaller files are produced by local
post-processing (`postprocess.sh`, used automatically by `generate.sh`):

- Output extension `.jpg` / `.jpeg` converts to JPEG (`NANO_BANANA_JPEG_QUALITY`, default 85).
- `NANO_BANANA_MAX_DIM=800` downscales the longest side to 800 px.
- Typical result: 1.5 MB PNG becomes a 100-200 KB JPEG.
- Requires one of: ImageMagick, `sips` (built into macOS), or Pillow.
  Plain `.png` output without `NANO_BANANA_MAX_DIM` needs no tools and keeps
  the original bytes.

## Settings (.env)

Copy `.env.example` to `.env` next to the script and fill in the values.
Process environment variables take precedence over `.env`.

| Variable | Required | Default | Meaning |
|----------|----------|---------|---------|
| `GEMINI_API_KEY` | yes | — | Google AI Studio API key |
| `GEMINI_IMAGE_MODEL` | no | `gemini-2.5-flash-image` | Image model to use |
| `GEMINI_ASPECT_RATIO` | no | model default (1:1) | API-side aspect ratio: `21:9`, `16:9`, `4:3`, `3:2`, `1:1`, `9:16`, `3:4`, `2:3`, `5:4`, `4:5` |
| `GEMINI_IMAGE_SIZE` | no | — | API-side resolution preset (`512px`, `1K`, `2K`, `4K`); Gemini 3.x image models only — 2.5 rejects it |
| `NANO_BANANA_MAX_DIM` | no | — | Downscale longest side to N px (local post-processing) |
| `NANO_BANANA_JPEG_QUALITY` | no | `85` | JPEG quality 1-100 for `.jpg` output |

## Verification

Criteria — the skill is ready only if all of these hold:

1. `generate.sh` and `postprocess.sh` pass a bash syntax check.
2. Called without a prompt, `generate.sh` prints usage to stderr and exits 2.
3. With an invalid API key, it prints the API error, creates no output file, and exits 1.
4. Post-processing (offline, no API): a locally crafted PNG converted with
   `NANO_BANANA_MAX_DIM=100` to `.jpg` produces a valid JPEG (magic bytes `FF D8`),
   downscaled to <= 100 px; a plain `.png` pass-through keeps the original bytes.
5. With a valid key, it generates a real image: exit 0, the output file exists,
   starts with the PNG magic bytes, and is larger than 5 KB.

Run: `./check.sh` (or `tools/check-skill.sh nano-banana` from the repo root).

Last verified: 2026-07-19 — `tools/check-skill.sh nano-banana` passed all checks, including real image generation.

