用途
generate-image 用于借助 AI 模型生成或编辑图像,覆盖通用图像生成需求,包括照片与写实图像、艺术插画与艺术作品、概念艺术与视觉概念、演示文稿或文档的视觉素材,以及图像编辑与修改。
如果需求是技术性示意图,例如流程图与过程图、电路图与电气原理图、生物通路与信号级联图、系统架构图、CONSORT 图与方法学流程图等,则应改用 scientific-schematics。
主要能力
该技能通过 OpenRouter 的图像生成模型生成和编辑高质量图像,涉及 FLUX.2 Pro 与 Gemini 3.1 Flash Image Preview 等模型。
可用模型:
- google/gemini-3.1-flash-image-preview:高质量,支持生成与编辑,为默认模型。
- black-forest-labs/flux.2-pro:快速、高质量,支持生成与编辑。
- black-forest-labs/flux.2-flex:快速且便宜,但质量不如 pro,仅支持生成。
选择建议:追求质量可用 gemini-3.1-flash-image-preview 或 flux.2-pro;需要编辑可用 gemini-3.1-flash-image-preview 或 flux.2-pro;考虑成本且仅需生成可用 flux.2-flex。
使用方式
使用 scripts/generate_image.py 脚本生成或编辑图像。
生成新图像: python scripts/generate_image.py "A beautiful sunset over mountains"
编辑已有图像: python scripts/generate_image.py "Make the sky purple" --input photo.jpg
脚本会生成或编辑图像,并保存为当前目录下的 generated_image.png。
API 密钥配置:脚本需要 OpenRouter API 密钥。运行前应检查用户是否已配置密钥:在项目目录或父目录中查找 .env 文件,检查其中是否有 OPENROUTER_API_KEY=<key>。如果未找到,需要提示用户创建 .env 文件并写入 OPENROUTER_API_KEY=your-api-key-here,或设置环境变量 export OPENROUTER_API_KEY=your-api-key-here。API 密钥可从 https://openrouter.ai/keys 获取。脚本会自动检测 .env 文件,并在缺少 API 密钥时给出清晰错误信息。
脚本参数:
- prompt(必填):要生成图像的文本描述,或编辑指令。
- --input 或 -i:用于编辑的输入图像路径(启用编辑模式)。
- --model 或 -m:OpenRouter 模型 ID,默认 google/gemini-3.1-flash-image-preview。
- --output 或 -o:输出文件路径,默认 generated_image.png。
- --api-key:OpenRouter API 密钥,可覆盖 .env 文件。
常见用法示例: 指定模型:python scripts/generate_image.py "A cat in space" --model "black-forest-labs/flux.2-pro" 自定义输出路径:python scripts/generate_image.py "Abstract art" --output artwork.png 编辑已有图像:python scripts/generate_image.py "Make the background blue" --input photo.jpg 用指定模型编辑:python scripts/generate_image.py "Add sunglasses to the person" --input portrait.png --model "black-forest-labs/flux.2-pro" 编辑并自定义输出:python scripts/generate_image.py "Remove the text from the image" --input screenshot.png --output cleaned.png 生成多张图像:多次运行脚本,使用不同提示词或输出路径,例如: python scripts/generate_image.py "Image 1 description" --output image1.png python scripts/generate_image.py "Image 2 description" --output image2.png
适用场景
科学文档:为论文生成概念插图,例如 python scripts/generate_image.py "Microscopic view of cancer cells being attacked by immunotherapy agents, scientific illustration style" --output figures/immunotherapy_concept.png;为演示生成视觉素材,例如 python scripts/generate_image.py "DNA double helix structure with highlighted mutation site, modern scientific visualization" --output slides/dna_mutation.png。
演示与海报:标题页背景,例如 python scripts/generate_image.py "Abstract blue and white background with subtle molecular patterns, professional presentation style" --output slides/background.png;海报主视觉,例如 python scripts/generate_image.py "Laboratory setting with modern equipment, photorealistic, well-lit" --output poster/hero.png。
通用视觉内容:网站或文档配图,例如 python scripts/generate_image.py "Professional team collaboration around a digital whiteboard, modern office" --output docs/team_collaboration.png;营销素材,例如 python scripts/generate_image.py "Futuristic AI brain concept with glowing neural networks" --output marketing/ai_concept.png。
限制与注意事项
脚本会针对缺少 API 密钥(附带设置说明)、API 错误(附带状态码)、意外响应格式、缺少依赖(requests 库)等情况给出清晰错误信息。如果脚本失败,应先阅读错误信息并解决问题后再重试。
图像以 base64 编码的数据 URL 返回,并自动保存为 PNG 文件。脚本支持不同 OpenRouter 模型返回的图像和内容响应格式。生成时间因模型而异,通常为 5-30 秒。进行图像编辑时,输入图像会被编码为 base64 并发送给模型。支持的输入图像格式为 PNG、JPEG、GIF、WebP。费用信息可查看 OpenRouter 定价:https://openrouter.ai/models。
图像编辑建议:明确说明想要的具体更改(例如“change the sky to sunset colors”而非“edit the sky”);尽可能引用图像中的具体元素;为获得最佳效果,使用清晰详细的编辑指令;Gemini 3.1 Flash Image Preview 与 FLUX.2 Pro 均通过 OpenRouter 支持图像编辑。
与其他技能集成:scientific-schematics 用于技术图表、流程图、电路、通路;generate-image 用于照片、插画、艺术作品、视觉概念;scientific-slides 可与 generate-image 结合制作视觉丰富的演示;latex-posters 可用 generate-image 制作海报视觉与主视觉图。