fix(skill): update descriptions and improve error handling in generate_image script

This commit is contained in:
nblog
2026-02-09 16:48:57 +08:00
parent 97bc889d9b
commit ef4aa0b2bc
2 changed files with 20 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
---
name: nano-banana-pro-openrouter
description: Generate or edit images via OpenRouter using openai-python with the Gemini 3 Pro Image model. Use for prompt-only image generation, image edits, and multi-image compositing; supports 1K/2K/4K output, saves results to the current working directory, and prints MEDIA lines.
description: 'Generate or edit images via OpenRouter with the Gemini 3 Pro Image model. Use for prompt-only image generation, image edits, and multi-image compositing; supports 1K/2K/4K output, saves results to the current working directory, and prints MEDIA lines.'
metadata:
emoji: 🍌
requires:
@@ -11,11 +11,12 @@ metadata:
primaryEnv: OPENROUTER_API_KEY
---
# Nano Banana Pro OpenRouter
## Overview
Generate or edit images with OpenRouter using the `google/gemini-3-pro-image-preview` model and the openai-python client. Support prompt-only generation, single-image edits, and multi-image composition. Save results to the current working directory and output MEDIA lines for easy attachment.
Generate or edit images with OpenRouter using the `google/gemini-3-pro-image-preview` model. Support prompt-only generation, single-image edits, and multi-image composition. Save results to the current working directory and output MEDIA lines for easy attachment.
### Prompt-only generation

View File

@@ -3,7 +3,6 @@
# requires-python = ">=3.10"
# dependencies = [
# "openai",
# "pillow",
# ]
# ///
"""
@@ -33,6 +32,8 @@ def parse_args():
parser.add_argument("--filename", required=True, help="Output filename (relative to CWD).")
parser.add_argument(
"--resolution",
type=str.upper,
choices=["1K", "2K", "4K"],
default="1K",
help="Output resolution: 1K, 2K, or 4K.",
)
@@ -70,13 +71,15 @@ def build_message_content(prompt: str, input_images):
content.append({"type": "image_url", "image_url": {"url": data_url}})
return content
def parse_data_url(data_url: str):
if not data_url.startswith("data:") or ";base64," not in data_url:
raise ValueError("Image URL is not a base64 data URL.")
header, encoded = data_url.split(",", 1)
mime = header[5:].split(";", 1)[0]
try:
raw = base64.b64decode(encoded)
except Exception as e:
raise SystemExit(f"Failed to decode base64 image payload: {e}")
return mime, raw