Loading...
Loading...
Image generation and editing using Google Gemini's Nano Banana Pro (gemini-3-pro-image-preview) model. Use when user requests: "Generate an image", "Create an image", "Make me a picture", "Draw", "Edit that image", "Change the color", "Remove background", "Add transparency", "Modify this image", "Make it transparent", "Change the style", "Add text to image", or any image creation/manipulation task. Supports text-to-image generation, image editing, multi-turn conversations, and transparency extraction via difference matting technique.
npx skill4agent add enzed/skills nano-banana-propip install google-genai Pillow numpy python-dotenv.envscripts/generate.py# Basic generation
python scripts/generate.py "a cute banana sticker" -o banana.png
# With transparency (for game assets, stickers, icons)
python scripts/generate.py "pixel art sword" -o sword.png --transparent
# Custom size and aspect ratio
python scripts/generate.py "game logo" -o logo.png --size 4K --ratio 16:9-o, --output--transparent--size--ratio--model.env| Intent | Triggers | Action |
|---|---|---|
| Generate | "create", "generate", "make", "draw", "design" | Text-to-image |
| Edit | "edit", "change", "modify", "update", "fix" | Image-to-image |
| Transparency | "transparent", "remove background", "alpha", "cutout", "PNG with transparency" | Use difference matting |
| Text overlay | "add text", "write on", "label", "caption" | Use Gemini 3 Pro for accurate text |
| Resolution | Best For | Pixel Output |
|---|---|---|
| 1K | Quick previews, thumbnails, web icons | ~1024px |
| 2K | Social media, standard web images | ~2048px |
| 4K | Print, professional assets, sprite sheets | ~4096px |
1:12:33:23:44:34:55:49:1616:921:91:19:163:416:93:221:9from google import genai
from google.genai import types
from PIL import Image
import io
client = genai.Client()
response = client.models.generate_content(
model="gemini-3-pro-image-preview",
contents="Your descriptive prompt here",
config=types.GenerateContentConfig(
response_modalities=['IMAGE'],
image_config=types.ImageConfig(
aspect_ratio="1:1", # or other ratio
image_size="2K" # 1K, 2K, or 4K
),
),
)
# Extract image from response
for part in response.parts:
if part.inline_data is not None:
image = Image.open(io.BytesIO(part.inline_data.data))
image.save("output.png")
break# Load existing image
input_image = Image.open("input.png")
response = client.models.generate_content(
model="gemini-3-pro-image-preview",
contents=[
input_image,
"Edit instruction: Change the background to sunset colors"
],
config=types.GenerateContentConfig(
response_modalities=['TEXT', 'IMAGE'],
image_config=types.ImageConfig(
aspect_ratio="1:1",
image_size="2K"
),
),
)# First edit
response1 = client.models.generate_content(
model="gemini-3-pro-image-preview",
contents=[image, "Add a red hat"],
config=config,
)
# Continue editing (include previous response)
response2 = client.models.generate_content(
model="gemini-3-pro-image-preview",
contents=[
image,
"Add a red hat",
response1, # Include for context preservation
"Now make the hat blue instead"
],
config=config,
)scripts/transparency.pyfrom scripts.transparency import extract_alpha_difference_matting
# After generating white and black background versions
final_image = extract_alpha_difference_matting(img_on_white, img_on_black)
final_image.save("output.png") # RGBA with true transparency"Describe the scene, don't just list keywords."
[Style/Medium] of [Subject] in [Context/Setting], [Lighting], [Additional details]# Photorealistic
A professional studio photograph of a brass steampunk pocket watch,
shot with a 50mm lens, soft diffused lighting from the left,
shallow depth of field with bokeh background, 4K HDR quality.
# Illustration
A detailed digital illustration of a medieval blacksmith's forge,
isometric perspective, warm orange glow from the furnace,
dieselpunk aesthetic with exposed pipes and riveted metal plates.
# Product mockup
A product photography shot of a ceramic coffee mug on a marble surface,
natural window lighting, minimalist Scandinavian style, clean white background.from google.genai import errors
def generate_with_retry(client, *, model, contents, config, max_attempts=5):
for attempt in range(1, max_attempts + 1):
try:
return client.models.generate_content(
model=model, contents=contents, config=config
)
except errors.APIError as e:
code = getattr(e, "code", None) or getattr(e, "status", None)
if code not in (429, 500, 502, 503, 504) or attempt >= max_attempts:
raise
delay = min(30, 2 ** (attempt - 1))
time.sleep(delay)| Model | Use Case |
|---|---|
| Complex edits, text rendering, multi-turn, transparency workflows |
| Quick generation, high volume, simple tasks |
| Photorealistic images, no editing needed |
scripts/generate.pyscripts/transparency.pyreferences/prompts.md