
Nano Banana 2
- 714 installs
- 281 repo stars
- Updated April 25, 2026
- intellectronica/agent-skills
nano-banana-2 is a Cursor and Claude Code skill that generates and edits images through Google's Gemini 3.1 Flash Image Preview API for developers who need fast visual iteration with controlled aspect ratio and resolutio
About
nano-banana-2 is an agent skill that wraps Google's Nano Banana 2 model (`gemini-3.1-flash-image-preview`) in a Python script runnable via `uv run`. Developers pass a text prompt to `generate_image.py` to create new images or edit existing ones, with explicit aspect-ratio control and output sizes from 512px through 4K. The skill installs under `.agents/skills/nano-banana-2/` and is triggered when a user asks to create, modify, or iterate on images inside Cursor or Claude Code. Reach for nano-banana-2 when you need quick visual drafts for UI concepts, app store screenshots, documentation diagrams, or marketing creatives without leaving the coding agent. It requires a Gemini API key and network access but keeps iteration inside the agent workflow instead of switching to a separate design tool.
- Generates new images from text prompts with explicit resolution and aspect-ratio control
- Edits existing images using one or more reference images plus editing instructions
- Supports four resolution modes: 512px (fastest), 1K (default), 2K, and 4K
- Runs via simple CLI with uv from the active project directory so outputs land in context
- Dedicated to the gemini-3.1-flash-image-preview model (Nano Banana 2)
Nano Banana 2 by the numbers
- 714 all-time installs (skills.sh)
- +31 installs in the week ending Aug 2, 2026 (Skillselion tracking)
- Ranked #330 of 1,335 Generative Media skills by installs in the Skillselion catalog
- Data as of Aug 2, 2026 (Skillselion catalog sync)
npx skills add https://github.com/intellectronica/agent-skills --skill nano-banana-2Add your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 714 |
|---|---|
| repo stars | ★ 281 |
| Last updated | April 25, 2026 |
| Repository | intellectronica/agent-skills ↗ |
How do you generate images from Cursor with Gemini?
Generate and edit images on demand directly from Cursor or Claude Code using Google's Gemini 3.1 Flash Image Preview model.
Who is it for?
Developers prototyping UI visuals, docs illustrations, or marketing assets who want Gemini 3.1 Flash Image Preview generation inside Cursor or Claude Code.
Skip if: Developers who need vector/SVG workflows, batch video generation, or a hosted design editor rather than API-driven image scripts.
When should I use this skill?
The user asks to create, edit, or iterate on images with aspect-ratio or resolution control using Nano Banana 2 or Gemini Flash Image Preview.
What you get
Generated or edited image files at chosen resolution and aspect ratio, saved from the `generate_image.py` script output.
- PNG or JPEG image files
- Edited image variants from prompts
By the numbers
- Supports image resolutions from 512px through 4K
- Uses the `gemini-3.1-flash-image-preview` model identifier
Files
Nano Banana 2 Image Generation & Editing
Generate new images or edit existing images with Nano Banana 2 (gemini-3.1-flash-image-preview).
Usage
Run the script using absolute or workspace-relative path (do NOT cd into the skill directory first):
Generate new image:
uv run ./.agents/skills/nano-banana-2/scripts/generate_image.py --prompt "your image description" --filename "output-name.png" [--resolution 512px|1K|2K|4K] [--aspect-ratio RATIO] [--api-key KEY]Edit image(s) with references:
uv run ./.agents/skills/nano-banana-2/scripts/generate_image.py --prompt "editing instructions" --filename "output-name.png" --input-image "path/to/input1.png" [--input-image "path/to/input2.png" ...] [--resolution 512px|1K|2K|4K] [--aspect-ratio RATIO] [--api-key KEY]Always run from the user's current working directory so outputs are saved in the active project context.
Model
Use model code:
gemini-3.1-flash-image-preview(Nano Banana 2)
Do not use gemini-3-pro-image-preview in this skill.
Resolution Options
Nano Banana 2 supports:
512px(fastest, low-latency iteration)1K(default)2K4K
Map common user language:
- "quick draft", "thumbnail", "tiny", "512", "0.5K" →
512px - no resolution mention →
1K - "2K", "medium", "normal" →
2K - "4K", "high-res", "ultra", "print quality" →
4K
Use uppercase K for 1K, 2K, 4K.
Aspect Ratios
Supported aspect ratios:
1:1,1:4,1:8,2:3,3:2,3:4,4:1,4:3,4:5,5:4,8:1,9:16,16:9,21:9
Map common requests:
- square post / icon →
1:1 - phone wallpaper / vertical reel →
9:16 - widescreen / slide / hero image →
16:9 - cinematic wide →
21:9 - portrait print →
2:3or3:4 - panorama banner →
4:1or8:1
If unspecified, let the model default behavior apply.
Reference Images (New in Gemini 3 Image workflows)
Provide up to 14 reference images when needed by repeating --input-image:
- preserve character consistency
- preserve object fidelity
- combine multiple visual references into one output
Use one image for simple edits; use multiple images for composition or consistency-sensitive tasks.
API Key
Resolve API key in this order: 1. --api-key argument 2. GEMINI_API_KEY environment variable
If no key is available, stop and report a clear error.
Filename Generation
Generate filenames as: yyyy-mm-dd-hh-mm-ss-name.png
Examples:
2026-02-26-17-31-04-japanese-garden.png2026-02-26-17-31-59-social-banner.png
Prompt Handling
For generation, pass the user's request as-is unless critically underspecified. For editing, include explicit transformation instructions in the prompt and preserve the original intent.
Output
- Save PNG to the current directory (or to a provided path in
--filename) - Return the full saved path(s)
- Do not read the output image back unless explicitly requested
Examples
Create a 4K widescreen image:
uv run ./.agents/skills/nano-banana-2/scripts/generate_image.py --prompt "Futuristic city skyline at blue hour with neon reflections" --filename "2026-02-26-17-45-00-futuristic-skyline.png" --resolution 4K --aspect-ratio 16:9Edit with multiple references:
uv run ./.agents/skills/nano-banana-2/scripts/generate_image.py --prompt "Create a polished campaign image that keeps the exact logo details and character identity" --filename "2026-02-26-17-50-10-campaign-image.png" --input-image "logo.png" --input-image "character.png" --resolution 2K --aspect-ratio 4:5#!/usr/bin/env python3
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "google-genai>=1.65.0",
# "pillow>=12.1.1",
# ]
# ///
"""
Generate and edit images using Nano Banana 2 (Gemini 3.1 Flash Image Preview).
Usage examples:
uv run ./.agents/skills/nano-banana-2/scripts/generate_image.py \
--prompt "A serene Japanese garden at sunrise" \
--filename "output.png" \
--resolution 2K \
--aspect-ratio 16:9
uv run ./.agents/skills/nano-banana-2/scripts/generate_image.py \
--prompt "Turn this into a cinematic poster" \
--filename "edited.png" \
--input-image "input.png" \
--resolution 4K
"""
import argparse
import os
import sys
from io import BytesIO
from pathlib import Path
SUPPORTED_ASPECT_RATIOS = [
"1:1", "1:4", "1:8", "2:3", "3:2", "3:4", "4:1",
"4:3", "4:5", "5:4", "8:1", "9:16", "16:9", "21:9",
]
SUPPORTED_RESOLUTIONS = ["512px", "1K", "2K", "4K"]
MAX_REFERENCE_IMAGES = 14
def get_api_key(provided_key: str | None) -> str | None:
"""Get API key from argument first, then environment."""
if provided_key:
return provided_key
return os.environ.get("GEMINI_API_KEY")
def save_png(image, output_path: Path) -> None:
"""Save image as PNG in RGB mode."""
if image.mode == "RGBA":
rgb_image = image.convert("RGB")
rgb_image.save(str(output_path), "PNG")
elif image.mode == "RGB":
image.save(str(output_path), "PNG")
else:
image.convert("RGB").save(str(output_path), "PNG")
def auto_detect_resolution(input_images, user_resolution: str) -> str:
"""Auto-select output size from input references when user left default 1K."""
if user_resolution != "1K" or not input_images:
return user_resolution
max_dim = max(max(image.size) for image in input_images)
if max_dim >= 3000:
return "4K"
if max_dim >= 1500:
return "2K"
if max_dim <= 640:
return "512px"
return "1K"
def main() -> None:
parser = argparse.ArgumentParser(
description="Generate/edit images with Nano Banana 2 (gemini-3.1-flash-image-preview)"
)
parser.add_argument("--prompt", "-p", required=True, help="Image prompt/instructions")
parser.add_argument("--filename", "-f", required=True, help="Output filename (.png recommended)")
parser.add_argument(
"--input-image",
"-i",
action="append",
default=[],
help=(
"Optional reference/input image path. Repeat flag for multiple images "
f"(up to {MAX_REFERENCE_IMAGES})."
),
)
parser.add_argument(
"--resolution",
"-r",
choices=SUPPORTED_RESOLUTIONS,
default="1K",
help="Output resolution: 512px, 1K (default), 2K, or 4K",
)
parser.add_argument(
"--aspect-ratio",
"-a",
choices=SUPPORTED_ASPECT_RATIOS,
help="Optional output aspect ratio",
)
parser.add_argument("--api-key", "-k", help="Gemini API key (overrides GEMINI_API_KEY)")
args = parser.parse_args()
api_key = get_api_key(args.api_key)
if not api_key:
print("Error: No API key provided.", file=sys.stderr)
print("Provide --api-key or set GEMINI_API_KEY.", file=sys.stderr)
sys.exit(1)
if len(args.input_image) > MAX_REFERENCE_IMAGES:
print(
f"Error: Too many input images ({len(args.input_image)}). "
f"Maximum supported: {MAX_REFERENCE_IMAGES}.",
file=sys.stderr,
)
sys.exit(1)
from google import genai
from google.genai import types
from PIL import Image as PILImage
client = genai.Client(api_key=api_key)
output_path = Path(args.filename)
output_path.parent.mkdir(parents=True, exist_ok=True)
input_images = []
if args.input_image:
for image_path in args.input_image:
try:
image = PILImage.open(image_path)
input_images.append(image)
print(f"Loaded input image: {image_path}")
except Exception as exc:
print(f"Error loading input image '{image_path}': {exc}", file=sys.stderr)
sys.exit(1)
output_resolution = auto_detect_resolution(input_images, args.resolution)
image_config_kwargs = {"image_size": output_resolution}
if args.aspect_ratio:
image_config_kwargs["aspect_ratio"] = args.aspect_ratio
if input_images:
contents = [args.prompt, *input_images]
print(
"Editing/generating from references "
f"({len(input_images)} image(s)), resolution {output_resolution}"
+ (f", aspect ratio {args.aspect_ratio}" if args.aspect_ratio else "")
+ "..."
)
else:
contents = [args.prompt]
print(
f"Generating image with resolution {output_resolution}"
+ (f", aspect ratio {args.aspect_ratio}" if args.aspect_ratio else "")
+ "..."
)
try:
response = client.models.generate_content(
model="gemini-3.1-flash-image-preview",
contents=contents,
config=types.GenerateContentConfig(
response_modalities=["TEXT", "IMAGE"],
image_config=types.ImageConfig(**image_config_kwargs),
),
)
image_parts = 0
saved_paths = []
for part in response.parts:
if part.text is not None:
print(f"Model response: {part.text}")
elif part.inline_data is not None:
image_parts += 1
image_data = part.inline_data.data
if isinstance(image_data, str):
import base64
image_data = base64.b64decode(image_data)
image = PILImage.open(BytesIO(image_data))
if image_parts == 1:
current_path = output_path
else:
current_path = output_path.with_name(
f"{output_path.stem}-{image_parts}{output_path.suffix or '.png'}"
)
save_png(image, current_path)
saved_paths.append(current_path.resolve())
if saved_paths:
print("\nSaved image file(s):")
for path in saved_paths:
print(path)
else:
print("Error: No image was generated in the response.", file=sys.stderr)
sys.exit(1)
except Exception as exc:
print(f"Error generating image: {exc}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()
Related skills
How it compares
Choose nano-banana-2 when you need Gemini Flash Image Preview inside Cursor or Claude Code with script-level aspect-ratio and resolution control.
FAQ
What model does nano-banana-2 use?
nano-banana-2 calls Google's Nano Banana 2 model, documented as `gemini-3.1-flash-image-preview`, through a bundled Python script for generation and editing from agent sessions.
What image resolutions does nano-banana-2 support?
nano-banana-2 exposes resolution control from 512px up to 4K, plus explicit aspect-ratio settings, so developers can match UI, store, or docs dimensions without post-processing.
How do you run nano-banana-2 from an agent?
nano-banana-2 runs `uv run ./.agents/skills/nano-banana-2/scripts/generate_image.py --prompt "..."` using an absolute or workspace-relative path, without changing into the skill folder first.