AgentSkillsCN

nanobanana

利用Google Gemini或OpenAI GPT Image模型生成与编辑图像。当用户发出“生成一张图像”、“创作一幅插画”、“编辑这张图像”等请求时,自动启用此功能。同时支持生成贴纸卡片,并可根据“制作一些贴纸”或“生成多个图标并进行拆分”等请求,进行贴纸与图标分割。可在Gemini(Nano Banana)与OpenAI(gpt-image-1.5)两大供应商之间自由选择。

SKILL.md
--- frontmatter
name: nanobanana
description: Generate and edit images using Google Gemini or OpenAI GPT Image models. Automatically used for requests like "generate an image", "create an illustration", "edit this image". Also supports sticker sheet generation and splitting for requests like "create some stickers" or "generate multiple icons and split them". Choose between Gemini (Nano Banana) and OpenAI (gpt-image-1.5) providers.
allowed-tools: Bash, Read, Write, AskUserQuestion

Nano Banana Image Generation Skill

Generate and edit images using Google Gemini or OpenAI GPT Image.


Referencing Pasted Images

When images are pasted into Claude Code, they are cached at ~/.claude/image-cache/. Copy from this cache to tmp and use as reference image.

How to Get Image Path (Recommended)

Important: When an image is pasted, always save it to tmp before using.

  1. User pastes an image
  2. Check the image-cache path from Additional working directories in environment info
    • Example: /Users/username/.claude/image-cache/0353f5a1-9885-4743-a956-d2d195b445d4
  3. Copy the image file from that directory to tmp
  4. Pass the tmp path to the -r option

Command to Save Image to tmp

bash
# 1. Check image-cache path (from Additional working directories in environment info)
# Example: /Users/username/.claude/image-cache/0353f5a1-9885-4743-a956-d2d195b445d4

# 2. Check images in cache
ls ~/.claude/image-cache/<session-id>/

# 3. Copy to tmp
cp ~/.claude/image-cache/<session-id>/*.png /tmp/reference_image.png

# 4. Use as reference image
python3 ~/.claude/skills/nanobanana/generate.py "Same style. Object: cat" \
  -r "/tmp/reference_image.png" -o cat.png

Example: Generate Using Pasted Image as Reference

bash
# 1. Copy latest image from image-cache to tmp
cp ~/.claude/image-cache/0353f5a1-9885-4743-a956-d2d195b445d4/3.png /tmp/reference_image.png

# 2. Gemini: Copy reference image style
python3 ~/.claude/skills/nanobanana/generate.py "Same style. Object: cat" \
  -r "/tmp/reference_image.png" -o cat.png

# 3. OpenAI: Edit reference image
python3 ~/.claude/skills/nanobanana/generate_openai.py "Change background to night sky" \
  -r "/tmp/reference_image.png" -o edited.png

Legacy Method (When Path is in Metadata)

If image metadata contains [Image: source: /path/to/image.png], use that path directly.

bash
python3 ~/.claude/skills/nanobanana/generate.py "Same style. Object: cat" \
  -r "/Users/user/Desktop/reference.png" -o cat.png

Note: Always wrap paths containing spaces in double quotes.


Pre-generation Confirmation Flow

Important: Before starting image generation, always confirm the following using the AskUserQuestion tool.

Confirmation Items

Common (Always Confirm):

ItemOptionsDescription
Providergemini / openaigemini=Nano Banana, openai=GPT Image
ModelGemini: pro/flash, OpenAI: 1.5/1/miniSee details below
Reference ImageYes / NoWhether there's a source image to copy style from (pasted images can be used)
Background RemovalVision API / Magenta removal / OpenAI transparent / Not neededSee methods below

Additional for Multiple Image Generation:

ItemOptionsDescription
Generation MethodSheet→split / Parallel generationSheet→split recommended (efficient)

Provider Characteristics

ProviderStrengthsAPI Key Environment Variable
GeminiJapanese prompts, reference image style copyingGEMINI_API_KEY
OpenAIHigh quality, native transparent background, multiple simultaneous generationOPENAI_API_KEY

Model Comparison

Gemini:

ModelIDFeatures
Flashgemini-2.5-flash-imageFast, cost-efficient
Progemini-3-pro-image-previewHigh quality, handles complex instructions

OpenAI:

ModelIDFeatures
GPT Image 1.5gpt-image-1.5Latest & highest quality (recommended)
GPT Image 1gpt-image-1Standard model
GPT Image Minigpt-image-1-miniLightweight, fast, low cost

Background Removal Method Selection

MethodBest ForProvider
OpenAI TransparentUse --background transparent for direct transparent generation with OpenAIOpenAI only
Vision APIReal photos, photo-style, complex backgrounds, gradient backgroundsGemini
Magenta RemovalIllustrations, simple shapes, line art, flat designGemini

Recommended Settings

CaseProviderModelBackground Removal
Transparent icons/stickersOpenAI1.5--background transparent
Reference image style copyGeminiproVision API
Simple illustrationsGeminiflashMagenta removal
High quality illustrationsOpenAI1.5None or transparent
Prototype/testingOpenAIminiNone

Tool List

ToolDescription
generate.pyGemini image generation
generate_openai.pyOpenAI image generation
remove-bg-magenta.pyMagenta background removal (includes 1px erosion)
remove-bg-vision.pyVision API background removal
erode.pyTransparent image edge erosion
split_transparent.pySplit transparent image into individual objects

Prerequisites

  1. For Gemini: Set environment variable GEMINI_API_KEY
  2. For OpenAI: Set environment variable OPENAI_API_KEY
  3. Vision API: Requires macOS 14.0 (Sonoma) or later

1. generate.py - Gemini Image Generation

bash
python3 ~/.claude/skills/nanobanana/generate.py "prompt" [options]

Options

OptionDescriptionDefault
-o, --outputOutput file pathgenerated_image.png
-a, --aspect-ratioAspect ratio (1:1, 16:9, 9:16, 4:3, 3:4)1:1
-m, --modelModel (flash, pro)pro
--magenta-bgGenerate with magenta backgroundNone
-r, --referenceReference image pathNone

Examples

bash
# Simple generation
python3 ~/.claude/skills/nanobanana/generate.py "cute cat illustration"

# Copy reference image style
python3 ~/.claude/skills/nanobanana/generate.py "Same exact style as this image. Object: coffee cup. NO text." -r reference.png -o coffee.png

# Generate with magenta background (for later transparency processing)
python3 ~/.claude/skills/nanobanana/generate.py "simple star icon" --magenta-bg -o star.png

2. generate_openai.py - OpenAI Image Generation

bash
python3 ~/.claude/skills/nanobanana/generate_openai.py "prompt" [options]

Options

OptionDescriptionDefault
-o, --outputOutput file pathgenerated_image.png
-s, --sizeSize (1024x1024, 1536x1024, 1024x1536, auto)1024x1024
-m, --modelModel (gpt-image-1, gpt-image-1-mini, gpt-image-1.5)gpt-image-1.5
-q, --qualityQuality (low, medium, high)medium
-b, --backgroundBackground (transparent, opaque, auto)auto
-f, --formatOutput format (png, jpeg, webp)png
-r, --referenceImage path to editNone
-n, --numberNumber of images to generate (1-10)1

Examples

bash
# Simple generation
python3 ~/.claude/skills/nanobanana/generate_openai.py "cute cat illustration"

# Generate with transparent background (no background removal needed)
python3 ~/.claude/skills/nanobanana/generate_openai.py "simple star icon" -b transparent -o star.png

# High quality, landscape
python3 ~/.claude/skills/nanobanana/generate_openai.py "sunset landscape" -s 1536x1024 -q high -o sunset.png

# Generate multiple simultaneously
python3 ~/.claude/skills/nanobanana/generate_openai.py "cute animal icon, single animal" -n 5 -b transparent -o animals.png

# Image editing
python3 ~/.claude/skills/nanobanana/generate_openai.py "change background to night sky" -r input.png -o edited.png

3. remove-bg-magenta.py - Magenta Background Removal

Remove magenta/pink background using color-based detection.

bash
python3 ~/.claude/skills/nanobanana/remove-bg-magenta.py input_image [-o output_image]

How it Works

  • Makes colors with R>180, G<100, B>100 transparent
  • 1px erosion removes pink edge residue

4. remove-bg-vision.py - Vision API Background Removal

Automatically detect and remove background using macOS Vision API.

bash
python3 ~/.claude/skills/nanobanana/remove-bg-vision.py input_image [-o output_image]

Features

  • Automatic foreground detection
  • Best for images maintaining reference image style (including background)
  • Requires macOS 14.0 or later

5. erode.py - Edge Erosion

Erode transparent image edges by specified pixels.

bash
python3 ~/.claude/skills/nanobanana/erode.py input_image [-o output_image] [-i iterations]
OptionDescriptionDefault
-o, --outputOutput image pathOverwrites input
-i, --iterationsErosion amount (pixels)1

6. split_transparent.py - Transparent Image Splitting

Split transparent PNG into individual objects (for sticker sheets).

bash
python3 ~/.claude/skills/nanobanana/split_transparent.py input_image [output_directory]

How it Works

  • Detects boundaries using alpha channel (transparent areas)
  • Extracts each connected component
  • Numbers from top-left to bottom-right

Workflow Examples

Generate Using Pasted Image as Reference (Recommended)

When user pastes an image, copy from image-cache to tmp and use as reference.

bash
# 1. Check image-cache path from Additional working directories in environment info
# Example: /Users/username/.claude/image-cache/0353f5a1-9885-4743-a956-d2d195b445d4

# 2. Copy from image-cache to tmp
cp ~/.claude/image-cache/0353f5a1-9885-4743-a956-d2d195b445d4/*.png /tmp/reference_image.png

# 3. Gemini: Generate different object in same style
python3 ~/.claude/skills/nanobanana/generate.py "Same exact style as this image. Object: coffee cup. NO text." \
  -r "/tmp/reference_image.png" -o coffee.png

# 4. OpenAI: Edit image
python3 ~/.claude/skills/nanobanana/generate_openai.py "change background to outer space" \
  -r "/tmp/reference_image.png" -o space.png

OpenAI: Transparent Icon Generation (Recommended - Simplest)

bash
# Generate transparent PNG in one step
python3 ~/.claude/skills/nanobanana/generate_openai.py "simple star icon" -b transparent -o star.png

OpenAI: Multiple Icon Simultaneous Generation

bash
# Generate 5 transparent PNGs simultaneously
python3 ~/.claude/skills/nanobanana/generate_openai.py "cute animal icon, single animal" -n 5 -b transparent -o animal.png
# → animal_01.png, animal_02.png, ... will be generated

Gemini: Transparent Sticker Generation (Simple Objects)

bash
# 1. Generate with magenta background
python3 ~/.claude/skills/nanobanana/generate.py "simple star icon" --magenta-bg -o star.png

# 2. Remove magenta
python3 ~/.claude/skills/nanobanana/remove-bg-magenta.py star.png

Gemini: Reference Image Style Copy + Transparency

bash
# 1. Generate with reference image style (no magenta to maintain style)
python3 ~/.claude/skills/nanobanana/generate.py "Same exact style as this image. Object: coffee cup. NO text." -r reference.png -o coffee.png

# 2. Remove background with Vision API
python3 ~/.claude/skills/nanobanana/remove-bg-vision.py coffee.png

Gemini: Sticker Sheet Generation → Split

bash
# 1. Generate multiple stickers with magenta background
python3 ~/.claude/skills/nanobanana/generate.py \
  "Multiple separate kawaii stickers with LARGE gaps: coffee cup, donut, cat, star. Arranged in 2x2 grid, well separated." \
  --magenta-bg -o sheet.png

# 2. Make background transparent
python3 ~/.claude/skills/nanobanana/remove-bg-magenta.py sheet.png

# 3. Split into individual files
python3 ~/.claude/skills/nanobanana/split_transparent.py sheet.png ./stickers/

Prompt Tips:

  • LARGE gaps between them - Wide spacing
  • well separated - No overlapping
  • Arranged in XxY grid - Specify grid layout

File Structure

code
~/.claude/skills/nanobanana/
├── SKILL.md               # This document
├── generate.py            # Gemini image generation
├── generate_openai.py     # OpenAI image generation
├── remove-bg-magenta.py   # Magenta background removal (includes 1px erosion)
├── remove-bg-vision.py    # Vision API background removal
├── remove-bg.swift        # Vision API implementation (Swift)
├── erode.py               # Edge erosion (standalone)
└── split_transparent.py   # Transparent image splitting