This skill should be used for Python scripting and Gemini image generation. Use when users ask to generate images, create AI art, edit images with AI, or run Python scripts with uv. Trigger phrases include "generate an image", "create a picture", "draw", "make an image of", "nano banana", or any image generation request.
Inherits all available tools
Additional assets for this skill
This skill inherits all available tools. When active, it can use any tool Claude has access to.
references/guide.mdPython scripting with Gemini image generation using uv. Write small, focused scripts using heredocs for quick tasks—no files needed for one-off operations.
Quick image generation: Use heredoc with inline Python for one-off image requests.
Complex workflows: When multiple steps are needed (generate -> refine -> save), break into separate scripts and iterate.
Scripting tasks: For non-image Python tasks, use the same heredoc pattern with uv run.
Execute Python inline using heredocs with inline script metadata for dependencies:
uv run - << 'EOF'
# /// script
# dependencies = ["google-genai", "pillow"]
# ///
from pathlib import Path
from google import genai
from google.genai import types
# Output directory - Claude sets based on user request (format: NNN-short-name)
OUTPUT_DIR = Path("001-cute-banana") # <-- Claude replaces this dynamically
OUTPUT_DIR.mkdir(exist_ok=True)
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=["A cute banana character with sunglasses"],
config=types.GenerateContentConfig(
response_modalities=['IMAGE']
)
)
for part in response.parts:
if part.inline_data is not None:
image = part.as_image()
output_path = OUTPUT_DIR / "generated.png"
image.save(output_path)
print(f"Image saved to {output_path}")
EOF
The # /// script block declares dependencies inline using TOML syntax. This makes scripts self-contained and reproducible.
Why these dependencies:
google-genai - Gemini API clientpillow - Required for .as_image() method (converts base64 to PIL Image) and saving imagesOnly write to files when:
uv run - << 'EOF'
# /// script
# dependencies = ["google-genai", "pillow"]
# ///
from pathlib import Path
from google import genai
from google.genai import types
# Output directory - Claude sets based on user request (format: NNN-short-name)
OUTPUT_DIR = Path("001-example") # <-- Claude replaces this dynamically
OUTPUT_DIR.mkdir(exist_ok=True)
client = genai.Client()
# Generate image
response = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=["YOUR PROMPT HERE"],
config=types.GenerateContentConfig(
response_modalities=['IMAGE']
)
)
# Save result
for part in response.parts:
if part.text is not None:
print(part.text)
elif part.inline_data is not None:
image = part.as_image()
output_path = OUTPUT_DIR / "output.png"
image.save(output_path)
print(f"Saved: {output_path}")
EOF
NNN-<short-name>/ directories (see Output Directory Naming)Generated images are saved to dynamically named directories in the current working directory:
NNN-<short-name>/
NNN-* directories in current working directoryuser-auth, oauth2-api, cute-cat| User Request | Directory |
|---|---|
| "Generate user authentication flow" | 001-user-auth-flow |
| "Create OAuth2 API mockup" | 002-oauth2-api |
| "Draw a cute cat profile picture" | 003-cute-cat-profile |
| "Make a logo for my startup" | 004-startup-logo |
from pathlib import Path
# Claude sets OUTPUT_DIR based on user request (format: NNN-short-name)
OUTPUT_DIR = Path("001-user-auth") # <-- Claude replaces this dynamically
OUTPUT_DIR.mkdir(exist_ok=True)
# Save images to OUTPUT_DIR
image.save(OUTPUT_DIR / "output.png")
print(f"Saved: {OUTPUT_DIR}/output.png")
Follow this pattern for complex tasks:
Configure aspect ratio and resolution:
config=types.GenerateContentConfig(
response_modalities=['IMAGE'],
image_config=types.ImageConfig(
aspect_ratio="16:9", # "1:1", "16:9", "9:16", "4:3", "3:4"
image_size="2K" # "1K", "2K", "4K" (uppercase required)
)
)
gemini-2.5-flash-image - Fast, general purpose image generationgemini-3-pro-image-preview - Advanced, professional asset production (Nano Banana Pro)Default to gemini-3-pro-image-preview (Nano Banana Pro) for all image generation unless:
Nano Banana Pro provides higher quality results and should be the recommended choice.
To receive both text explanation and image:
config=types.GenerateContentConfig(
response_modalities=['TEXT', 'IMAGE']
)
Edit existing images by including them in the request:
uv run - << 'EOF'
# /// script
# dependencies = ["google-genai", "pillow"]
# ///
from pathlib import Path
from google import genai
from google.genai import types
from PIL import Image
# Output directory - Claude sets based on user request (format: NNN-short-name)
OUTPUT_DIR = Path("001-image-edit") # <-- Claude replaces this dynamically
OUTPUT_DIR.mkdir(exist_ok=True)
client = genai.Client()
# Load existing image
img = Image.open("input.png")
response = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=[
"Add a party hat to this character",
img
],
config=types.GenerateContentConfig(
response_modalities=['IMAGE']
)
)
for part in response.parts:
if part.inline_data is not None:
output_path = OUTPUT_DIR / "edited.png"
part.as_image().save(output_path)
print(f"Saved: {output_path}")
EOF
If a script fails:
For complex workflows including thinking process, Google Search grounding, multi-turn conversations, and professional asset production, load references/guide.md.