gemini-image-generation

使用 Gemini 通过 Google GenAI SDK 生成或编辑图像,支持文本转图与图像修改。

已扫描
适合谁
需要快速生成创意图像的设计师、希望自动化图像处理流程的开发者
不适合谁
无 API 密钥或网络访问权限的用户、不熟悉 Node.js 环境的初学者
国内可用性
需网络配置。可能需要网络配置或第三方服务可访问。
安装难度
新手友好(★☆☆)。基于终端操作、依赖、API Key 和本地环境要求的初步判断。

安装与下载

openclaw skills install @ztj7728/gemini-image-generation

Skill 说明

命令、参数、文件名以原文为准

图像生成

当需要根据文本提示创建一张或多张图像,或使用 Gemini 编辑一张或多张现有图像时,请使用此技能。

要求

  • ~/.openclaw/openclaw.json 中必须包含 $.skills.entries["gemini-image-generation"].enabled 设置为 true
  • ~/.openclaw/openclaw.json 中必须包含 $.skills.entries["gemini-image-generation"].env,并设置以下键值:

- GEMINI_API_KEY(必需)

- GEMINI_MODEL_ID(必需)

- GEMINI_BASE_URL(可选)

  • 示例 ~/.openclaw/openclaw.json
{
  ......,
  "skills": {
    "entries": {
      "gemini-image-generation": {
        "enabled": true,
        "env": {
          "GEMINI_API_KEY": "sk-xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
          "GEMINI_MODEL_ID": "gemini-3.1-flash-image-preview",
          "GEMINI_BASE_URL": "https://custom-endpoint.com"
        }
      }
    }
  },
  ......
}
  • 工作区环境中必须安装 Node.js。
  • 在技能根目录下首次运行 npm install 安装依赖。

使用场景

  • 用户要求根据文本提示生成新图像。
  • 用户要求修改、重风格化、扩展或以其他方式编辑一张或多张现有图像。
  • 用户希望将生成的图像保存到工作区文件中。
  • 任务应通过可复用的 OpenClaw 技能处理,而非临时编写 SDK 代码。

操作流程

  1. 将用户请求转化为一个清晰明确的图像生成提示。
  2. 若用户提供了源图像,请在工作区中选择或确认输入文件路径。
  3. 若用户指定了目标宽高比或尺寸,请通过 --aspectRatio--imageSize 参数传递。
  4. 除非用户已提供输出路径,否则在工作区中选择一个输出路径。
  5. 对于文生图,运行 [generate-image.mjs](./scripts/generate-image.mjs),传入 --prompt--output 及可选的图像配置参数。
  6. 对于图像编辑,运行 [edit-image.mjs](./scripts/edit-image.mjs),传入 --prompt、一个或多个 --input 值、--output 及可选的图像配置参数。
  7. 从环境变量中读取 GEMINI_API_KEY 获取 API 密钥,从 GEMINI_MODEL_ID 获取模型 ID。
  8. 可选地,从环境变量 GEMINI_BASE_URL 读取自定义端点地址。
  9. 返回保存的图像路径给用户。
  10. 每返回一个图像路径后,还需输出 MEDIA:<image_path>(例如:MEDIA:outputs/gemini-native-image.png),以便在对话中内联显示图像。

命令示例

node ./skills/gemini-image-generation/scripts/generate-image.mjs --prompt "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme" --output "outputs/gemini-native-image.png"
node ./skills/gemini-image-generation/scripts/generate-image.mjs --prompt "Create a wide cinematic food photo of a nano banana dish in a fancy restaurant with a Gemini theme" --output "outputs/gemini-wide.png" --aspectRatio "16:9" --imageSize "2K"
node ./skills/gemini-image-generation/scripts/edit-image.mjs --prompt "Turn this cat into a watercolor illustration eating a nano-banana in a fancy restaurant under the Gemini constellation" --input "inputs/cat.png" --output "outputs/cat-watercolor.png" --aspectRatio "5:4" --imageSize "2K"
node ./skills/gemini-image-generation/scripts/edit-image.mjs --prompt "Create an office group photo of these people making funny faces" --input "inputs/person-1.jpg" --input "inputs/person-2.jpg" --input "inputs/person-3.jpg" --output "outputs/group-photo.png"

注意事项

  • 脚本会输出 TEXT: 行用于模型文本响应,以及 IMAGE: 行用于每个保存的文件。
  • 技能执行完成后,必须对每张生成的图像输出 MEDIA:<path>,确保图像能在对话中内联显示,同时附带文件路径。
  • 最终的 JSON 总结仅包含生成的图像路径和可选的图像配置信息,不会回显提示内容、模型 ID 或源图像路径。
  • 保存的文件扩展名遵循返回图像的 MIME 类型。若指定的输出路径使用了不同的后缀,脚本将保留基础名称,并按实际返回类型写入文件。
  • 若模型返回多张图像,脚本会将其保存为 name-1.pngname-2.png 等形式。
  • edit-image.mjs 支持重复使用 --input 参数。也可将多个输入路径以逗号分隔,传入单个 --input 参数。
  • edit-image.mjs 会根据 .png.jpg.jpeg.webp 后缀推断源文件的 MIME 类型。可使用一个 --mime-type 适用于所有输入,或为每个 --input 重复指定 --mime-type 以一一对应。
  • 两个脚本均支持 --aspectRatio--imageSize 参数,也接受连字符形式 --aspect-ratio--image-size
  • 脚本仅在至少提供其中一个参数时才会发送 config.imageConfig
Z
@ztj7728

已收录 1 个 Skill

相关推荐