npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@max10240/opencode-plugin-image-gen

v1.0.39

Published

Generate and edit images in OpenCode through provider Images APIs

Readme

@max10240/opencode-plugin-image-gen

English | 简体中文

不离开对话,也能生成和编辑图片。

你在写 README,需要一张头图;你在做界面,想先看个 mockup;你有一张参考图,想试试换个风格。按以前的流程,得离开 OpenCode、 打开图片工具、下载文件,再回来描述你拿到了什么。

有了这个插件,直接开口就行。Agent 生成或编辑图片,保存到项目里;有预览能力时,还会在对话里显示出来。图片字节不会进入模型 上下文,Agent 的注意力仍然在任务上,而不是像素上。

什么时候需要它

  • 写作时需要插图、图标、mockup 或社交媒体图片。
  • 想通过描述来修改或重绘一张现有图片。
  • 想把生成的素材直接保存进仓库。
  • 不希望图片数据进入模型对话。
  • 已经在 OpenCode 里配置了 OpenAI 或其他支持的图片 provider。

它能给你什么

  • 一句话,一张图。 用自然语言告诉 Agent,它会替你调用工具。
  • 生成或编辑。 不提供参考图就是新生成;提供参考图就是编辑。
  • 安全的文件处理。 不覆盖已有文件,自动分配 -v2 之类的名称。
  • 内联预览。 预览插件可用时,图片显示在工具输出下方,可以放大查看。
  • 复用现有 provider 配置。 使用 OpenCode 里已经配置好的 provider 和凭据,不读取凭据文件,也不猜测密钥。
  • 图片字节不进对话。 模型只拿到确认信息和文件引用,拿不到图片本身。

快速开始

在 server 配置中加载。默认模型是 openai/gpt-image-2.5-sunburst:

{
  "$schema": "https://opencode.ai/config.json",
  "plugins": [{
    "package": "@max10240/opencode-plugin-image-gen",
    "options": { "model": "openai/gpt-image-2.5-sunburst" }
  }]
}

如果要用网关或其他 provider,在同一个配置里声明:

{
  "plugins": [{
    "package": "@max10240/opencode-plugin-image-gen",
    "options": { "model": "gateway/gpt-image-2.5-sunburst" }
  }],
  "providers": {
    "gateway": {
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": { "baseURL": "https://gateway.example/v1" },
      "headers": { "Authorization": "{env:GATEWAY_AUTH}" }
    }
  }
}

通过 Unicorn 使用时,生图默认开启:

{
  "plugins": [{
    "package": "@max10240/opencode-plugin-unicorn",
    "options": {
      "features": { "imageGen": true, "showImg": true },
      "imageGen": { "model": "openai/gpt-image-2.5-sunburst" }
    }
  }]
}

使用

直接说:

给 README 生成一张极简风格的风筝插图,保存为 docs/kite.png。

Agent 会调用 image_gen:

{ "prompt": "A red kite", "out": "kite.png" }

要编辑现有图片,加上 images。路径相对于当前 session 目录。

{
  "prompt": "把天空调暖一点,再加一朵小云",
  "out": "kite-v2.png",
  "images": ["kite.png"]
}

需要局部 mask 编辑时,加上 mask:

{
  "prompt": "只把标记区域替换成一朵小云",
  "out": "kite-masked.png",
  "images": ["kite.png"],
  "mask": "mask.png"
}

Mask 的具体语义由 provider 决定。OpenAI 用完全透明像素表示可编辑区,并要求 mask 与第一张参考图尺寸一致; 部分 provider 也接受白色(>127)区域。支持 masked compositing 的 provider 可以让 mask 外像素逐字节保持不变; 边界默认是硬合成,除非 provider 自己加羽化。这不一定是原生 inpaint。

可选字段:model、quality、size、images、mask。prompt 和 out 必填。

配置

| 设置 | 优先级 | 说明 | | --- | --- | --- | | 模型 | 工具参数 → options.model → openai/gpt-image-2.5-sunburst | 非 OpenAI provider 使用 provider/model | | 质量 | 工具参数 | low、medium、high、xhigh、max 或 auto;xhigh 和 max 需要模型支持 | | 尺寸 | 工具参数 | 取决于 provider 支持范围 | | 参考图 | 工具参数 | 相对于 session 目录 | | Mask | 工具参数 | 相对于 session 目录;需要参考图和 provider mask 支持 |

默认 provider 是 OpenAI,不会自动跟随当前对话模型。使用其他 provider 时,请写完整的 provider/model。你在 provider 中配置的 headers、base URL 和 variant 会被沿用。

注意事项

  • Provider 必须支持图片接口。 OpenAI-compatible endpoint 需要实现 /images/generations 和 /images/edits; 能对话不代表能生图。Mask 编辑还要求 /images/edits 支持 mask。
  • 生图和预览是分开的。 预览缺失、关闭或失败,不会影响生成的文件,也不会触发第二次生成。
  • 图片是文件引用,不是聊天附件。 图片保存在磁盘上,模型只拿到路径和预览引用。
  • 某些高级认证方式可能需要额外配置。 如果 provider 依赖其他插件来签名请求或注入路由,那部分行为不在本插件控制范围内。
  • 图片权限由 provider 决定。 凭据有效,不代表账号一定能使用图片模型。
  • 云平台认证可能需要额外验证。 AWS、Azure、Google ADC 等 provider 专属认证组合尚未使用真实云账号测试。
  • 不会在后台偷偷调用。 只有 Agent 调用工具时才会请求图片 API。