$npx -y skills add ReScienceLab/opc-skills --skill nanobananaGenerate and edit images using Google Gemini 3 Pro Image (Nano Banana Pro). Supports text-to-image, image editing, various aspect ratios, and high-resolution output (2K/4K). Use when user wants to generate images, create images, use Gemini image generation, or do AI image generat
| 1 | # Nano Banana - AI Image Generation |
| 2 | |
| 3 | Generate and edit images using Google's Gemini 3 Pro Image model (`gemini-3-pro-image-preview`, nicknamed "Nano Banana Pro" 🍌). |
| 4 | |
| 5 | ## Prerequisites |
| 6 | |
| 7 | **Required:** |
| 8 | - `GEMINI_API_KEY` - Get from [Google AI Studio](https://aistudio.google.com/apikey) |
| 9 | - Python 3.10+ with `google-genai` package |
| 10 | |
| 11 | **Install dependencies:** |
| 12 | ```bash |
| 13 | pip install google-genai pillow |
| 14 | ``` |
| 15 | |
| 16 | ## Quick Start |
| 17 | |
| 18 | ### Generate an image: |
| 19 | ```bash |
| 20 | python3 <skill_dir>/scripts/generate.py "a cute robot mascot, pixel art style" -o robot.png |
| 21 | ``` |
| 22 | |
| 23 | ### Edit an existing image: |
| 24 | ```bash |
| 25 | python3 <skill_dir>/scripts/generate.py "make the background blue" -i input.jpg -o output.png |
| 26 | ``` |
| 27 | |
| 28 | ### Generate with specific aspect ratio: |
| 29 | ```bash |
| 30 | python3 <skill_dir>/scripts/generate.py "cinematic landscape" --ratio 21:9 -o landscape.png |
| 31 | ``` |
| 32 | |
| 33 | ### Generate high-resolution 4K image: |
| 34 | ```bash |
| 35 | python3 <skill_dir>/scripts/generate.py "professional product photo" --size 4K -o product.png |
| 36 | ``` |
| 37 | |
| 38 | ## Script Reference |
| 39 | |
| 40 | ### `scripts/generate.py` |
| 41 | |
| 42 | Main image generation script. |
| 43 | |
| 44 | ``` |
| 45 | Usage: generate.py [OPTIONS] PROMPT |
| 46 | |
| 47 | Arguments: |
| 48 | PROMPT Text prompt for image generation |
| 49 | |
| 50 | Options: |
| 51 | -o, --output PATH Output file path (default: auto-generated) |
| 52 | -i, --input PATH Input image for editing (optional) |
| 53 | -r, --ratio RATIO Aspect ratio (1:1, 16:9, 9:16, 21:9, etc.) |
| 54 | -s, --size SIZE Image size: 2K or 4K (default: standard) |
| 55 | --search Enable Google Search grounding for accuracy |
| 56 | -v, --verbose Show detailed output |
| 57 | ``` |
| 58 | |
| 59 | **Supported aspect ratios:** |
| 60 | - `1:1` - Square (default) |
| 61 | - `2:3`, `3:2` - Portrait/Landscape |
| 62 | - `3:4`, `4:3` - Standard |
| 63 | - `4:5`, `5:4` - Photo |
| 64 | - `9:16`, `16:9` - Widescreen |
| 65 | - `21:9` - Ultra-wide/Cinematic |
| 66 | |
| 67 | ### `scripts/batch_generate.py` |
| 68 | |
| 69 | Generate multiple images with sequential naming. |
| 70 | |
| 71 | ``` |
| 72 | Usage: batch_generate.py [OPTIONS] PROMPT |
| 73 | |
| 74 | Arguments: |
| 75 | PROMPT Text prompt for image generation |
| 76 | |
| 77 | Options: |
| 78 | -n, --count N Number of images to generate (default: 10) |
| 79 | -d, --dir PATH Output directory |
| 80 | -p, --prefix STR Filename prefix (default: "image") |
| 81 | -r, --ratio RATIO Aspect ratio |
| 82 | -s, --size SIZE Image size (2K/4K) |
| 83 | --delay SECONDS Delay between generations (default: 3) |
| 84 | ``` |
| 85 | |
| 86 | **Example:** |
| 87 | ```bash |
| 88 | python3 <skill_dir>/scripts/batch_generate.py "pixel art logo" -n 20 -d ./logos -p logo |
| 89 | ``` |
| 90 | |
| 91 | ## Python API |
| 92 | |
| 93 | You can also use the module directly: |
| 94 | |
| 95 | ```python |
| 96 | from generate import generate_image, edit_image |
| 97 | |
| 98 | # Generate image |
| 99 | result = generate_image( |
| 100 | prompt="a futuristic city at night", |
| 101 | output_path="city.png", |
| 102 | aspect_ratio="16:9", |
| 103 | image_size="4K" |
| 104 | ) |
| 105 | |
| 106 | # Edit existing image |
| 107 | result = edit_image( |
| 108 | prompt="add flying cars to the sky", |
| 109 | input_path="city.png", |
| 110 | output_path="city_edited.png" |
| 111 | ) |
| 112 | ``` |
| 113 | |
| 114 | ## Environment Variables |
| 115 | |
| 116 | | Variable | Description | Default | |
| 117 | |----------|-------------|---------| |
| 118 | | `GEMINI_API_KEY` | Google Gemini API key | Required | |
| 119 | | `IMAGE_OUTPUT_DIR` | Default output directory | `./nanobanana-images` | |
| 120 | |
| 121 | ## Features |
| 122 | |
| 123 | ### Text-to-Image Generation |
| 124 | Create images from text descriptions. The model excels at: |
| 125 | - Photorealistic images |
| 126 | - Artistic styles (pixel art, illustration, etc.) |
| 127 | - Product photography |
| 128 | - Landscapes and scenes |
| 129 | |
| 130 | ### Image Editing |
| 131 | Transform existing images with natural language: |
| 132 | - Style transfer |
| 133 | - Object addition/removal |
| 134 | - Background changes |
| 135 | - Color adjustments |
| 136 | |
| 137 | ### High-Resolution Output |
| 138 | - **Standard**: Fast generation, good quality |
| 139 | - **2K**: Enhanced detail (2048px) |
| 140 | - **4K**: Maximum quality (3840px), best for text rendering |
| 141 | |
| 142 | ### Google Search Grounding |
| 143 | Enable `--search` for factually accurate images involving: |
| 144 | - Real people, places, landmarks |
| 145 | - Current events |
| 146 | - Specific products or brands |
| 147 | |
| 148 | ## Best Practices |
| 149 | |
| 150 | ### Prompt Writing |
| 151 | |
| 152 | **Good prompts include:** |
| 153 | - Subject description |
| 154 | - Style/aesthetic |
| 155 | - Lighting and mood |
| 156 | - Composition details |
| 157 | - Color palette |
| 158 | |
| 159 | **Example:** |
| 160 | ``` |
| 161 | "A cozy coffee shop interior, warm lighting, vintage aesthetic, |
| 162 | wooden furniture, plants on shelves, morning sunlight through windows, |
| 163 | soft focus background, 35mm film photography style" |
| 164 | ``` |
| 165 | |
| 166 | ### Batch Generation Tips |
| 167 | |
| 168 | 1. Generate 10-20 variations to explore options |
| 169 | 2. Use consistent prompts for style coherence |
| 170 | 3. Add 3-5 second delays to avoid rate limits |
| 171 | 4. Review results and iterate on best candidates |
| 172 | |
| 173 | ## Rate Limits |
| 174 | |
| 175 | - Gemini API has usage quotas |
| 176 | - Add delays between batch generations |
| 177 | - Check your quota at [Google AI Studio](https://aistudio.google.com/) |
| 178 | |
| 179 | ## Troubleshooting |
| 180 | |
| 181 | **"API key not found"** |
| 182 | - Set `GEMINI_API_KEY` environment variable |
| 183 | - Or pass via `--api-key` option |
| 184 | |
| 185 | **"No image in response"** |
| 186 | - Prompt may have triggered safety filters |
| 187 | - Try rephra |