mcpField
G
generate-image

generate-image

github.com/davila7创意与媒体33.0k1.4k 次安装1 天前更新
代码仓库

关于 generate-image

generate-image 是一项使用 OpenRouter 模型生成和编辑图像的技能,适用于制作照片、插画及其他视觉素材。它通过 Python 脚本提供模型选择,并可指定输入与输出路径。

主要功能

  1. 01根据文本提示生成图像
  2. 02按指令编辑现有图像
  3. 03选择 OpenRouter 模型
  4. 04指定输入和输出路径
  5. 05将结果保存为 PNG

适用场景

  1. 01制作演示文稿或文档配图
  2. 02创作概念艺术和插画
  3. 03修改现有照片或图像

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/davila7/claude-code-templates --skill generate-image

安装后在 Claude Code 中输入/generate-image确认已加载。

附带文件scripts/generate_image.py

详细介绍

生成图像

使用 OpenRouter 的图像生成模型(包括 FLUX.2 Pro 和 Gemini 3 Pro)生成和编辑高质量图像。

何时使用此技能

在以下情况下使用 generate-image:

  • 照片和逼真图像
  • 艺术插画和艺术作品
  • 概念艺术和视觉概念
  • 演示文稿或文档的视觉素材
  • 图像编辑和修改
  • 任何通用图像生成需求

在以下情况下改用 scientific-schematics:

  • 流程图和过程图
  • 电路图和电气原理图
  • 生物通路和信号级联
  • 系统架构图
  • CONSORT 图和方法流程图
  • 任何技术图或示意图

快速开始

使用 scripts/generate_image.py 脚本生成或编辑图像:

# Generate a new image
python scripts/generate_image.py "A beautiful sunset over mountains"

# Edit an existing image
python scripts/generate_image.py "Make the sky purple" --input photo.jpg

此操作会生成或编辑图像,并将其保存为当前目录下的 generated_image.png。

API 密钥设置

重要:此脚本需要 OpenRouter API 密钥。运行前,请检查用户是否已配置 API 密钥:

  1. 在项目目录或其父目录中查找 .env 文件
  2. 检查 .env 文件中是否包含 OPENROUTER_API_KEY=<key>
  3. 如果没有,请告知用户需要:
    • 创建包含 OPENROUTER_API_KEY=your-api-key-here 的 .env 文件
    • 或设置环境变量:export OPENROUTER_API_KEY=your-api-key-here
    • 从此处获取 API 密钥:https://openrouter.ai/keys

脚本会自动检测 .env 文件;如果缺少 API 密钥,则会提供清晰的错误消息。

模型选择

默认模型:google/gemini-3-pro-image-preview(高质量,推荐)

可用于生成和编辑的模型:

  • google/gemini-3-pro-image-preview - 高质量,支持生成和编辑
  • black-forest-labs/flux.2-pro - 速度快、质量高,支持生成和编辑

仅用于生成:

  • black-forest-labs/flux.2-flex - 速度快、成本低,但质量不如 pro

根据以下因素选择:

  • 质量:使用 gemini-3-pro 或 flux.2-pro
  • 编辑:使用 gemini-3-pro 或 flux.2-pro(两者都支持图像编辑)
  • 成本:仅生成时使用 flux.2-flex

常见用法

基本生成
python scripts/generate_image.py "Your prompt here"
指定模型
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

脚本参数

  • prompt(必需):要生成的图像的文字描述,或编辑说明
  • --input 或 -i:用于编辑的输入图像路径(启用编辑模式)
  • --model 或 -m:OpenRouter 模型 ID(默认值:google/gemini-3-pro-image-preview)
  • --output 或 -o:输出文件路径(默认值:generated_image.png)
  • --api-key:OpenRouter API 密钥(覆盖 .env 文件中的值)

示例用例

用于科学文档
# Generate a conceptual illustration for a paper
python scripts/generate_image.py "Microscopic view of cancer cells being attacked by immunotherapy agents, scientific illustration style" --output figures/immunotherapy_concept.png

# Create a visual for a presentation
python scripts/generate_image.py "DNA double helix structure with highlighted mutation site, modern scientific visualization" --output slides/dna_mutation.png
用于演示文稿和海报
# Title slide background
python scripts/generate_image.py "Abstract blue and white background with subtle molecular patterns, professional presentation style" --output slides/background.png

# Poster hero image
python scripts/generate_image.py "Laboratory setting with modern equipment, photorealistic, well-lit" --output poster/hero.png
用于通用视觉内容
# Website or documentation images
python scripts/generate_image.py "Professional team collaboration around a digital whiteboard, modern office" --output docs/team_collaboration.png

# Marketing materials
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 模型返回的 images 和 content 响应格式
  • 生成时间因模型而异(通常为 5–30 秒)
  • 编辑图像时,输入图像会编码为 base64 并发送给模型
  • 支持的输入图像格式:PNG、JPEG、GIF、WebP
  • 有关费用信息,请查看 OpenRouter 定价:https://openrouter.ai/models

图像编辑技巧

  • 明确说明想要更改的内容(例如,“将天空改成日落色调”,而不是“编辑天空”)
  • 尽可能在图像中指出具体元素
  • 为获得最佳效果,请使用清晰、详细的编辑说明
  • Gemini 3 Pro 和 FLUX.2 Pro 均支持通过 OpenRouter 编辑图像

与其他技能集成

  • scientific-schematics:用于技术图表、流程图、电路和路径图
  • generate-image:用于照片、插图、艺术作品和视觉概念
  • scientific-slides:与 generate-image 结合使用,制作视觉效果丰富的演示文稿
  • latex-posters:使用 generate-image 制作海报视觉素材和主视觉图

评论

支持 Markdown