返回顶部
g

grok-imagine-image-proxAI图像生成

Generiert hochwertige Bilder mit xAI Grok/Flux API. Use when user asks for image generation ("mach a Bild von...", "generier PNG...", "Bild erstellen") or image editing ("ändere das Bild", "mach daraus..."). Handles Prompts, styles, aspect ratios, edits, batch generation. Outputs PNG via base64 or file.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.2
安全检测
已通过
1,075
下载量
免费
免费
3
收藏
概述
安装方式
版本历史

grok-imagine-image-pro

Grok Imagine Image Pro

API Key:$XAIAPIKEY(已配置)
保存目录:~/.openclaw/media/(解析为 /data/.openclaw/media/——允许用于Telegram发送)

可用模型

  • - grok-imagine-image — 标准质量,速度更快
  • grok-imagine-image-pro — 更高质量(生成时的默认选项)

1. 图像生成

bash
curl -s https://api.x.ai/v1/images/generations \
-H Authorization: Bearer $XAIAPIKEY \
-H Content-Type: application/json \
--data {
model: grok-imagine-image-pro,
prompt: <提示词>,
n: 1,
responseformat: b64json
} | python3 -c
import json, sys, base64, os, time
os.makedirs(os.path.expanduser(~/.openclaw/media), exist_ok=True)
r = json.load(sys.stdin)
ts = int(time.time())
for i, img in enumerate(r[data]):
imgdata = base64.b64decode(img[b64json])
fpath = os.path.expanduser(f~/.openclaw/media/generated{ts}{i}.png)
with open(fpath, wb) as f:
f.write(img_data)
print(fpath)

宽高比

在JSON请求体中添加 aspect_ratio: <比例>。支持的数值:

比例使用场景
1:1社交媒体、缩略图
16:9 / 9:16
宽屏、手机故事 |
| 4:3 / 3:4 | 演示文稿、肖像 |
| 3:2 / 2:3 | 摄影 |
| 2:1 / 1:2 | 横幅、页眉 |
| auto | 模型自动选择最佳比例(默认) |

批量生成

设置 n: <数量>(1-10)可在一次请求中生成多张图像。

2. 图像编辑 / 风格迁移

通过提供源图像和编辑提示词来编辑现有图像。
使用相同的 /v1/images/generations 端点,额外添加 image_url 字段。

请勿使用 /v1/images/edits 配合 multipart 格式——xAI 要求使用 JSON。

重要提示: 对于本地文件,请使用 Python 构建 JSON 载荷文件,然后使用 @file 方式调用 curl。
在 curl 参数中内联 base64 编码会导致大于约100KB的图像出现参数列表过长错误。

注意: 这不是真正的图像编辑——API 会生成一张受源图像启发的新图像。
它无法进行像素级精确编辑(例如仅改变汽车颜色而保持其他所有内容不变)。

从本地文件编辑(推荐方法):

bash
python3 -c
import json, base64
with open(<源文件路径>, rb) as f:
b64 = base64.b64encode(f.read()).decode()
payload = {
model: grok-imagine-image,
prompt: <编辑提示词>,
image_url: fdata:image/png;base64,{b64},
n: 1,
responseformat: b64json
}
with open(/tmp/imgeditpayload.json, w) as f:
json.dump(payload, f)
print(载荷已就绪)
&& \
curl -s https://api.x.ai/v1/images/generations \
-H Authorization: Bearer $XAIAPIKEY \
-H Content-Type: application/json \
-d @/tmp/imgeditpayload.json | python3 -c
import json, sys, base64, os, time
os.makedirs(os.path.expanduser(~/.openclaw/media), exist_ok=True)
r = json.load(sys.stdin)
imgdata = base64.b64decode(r[data][0][b64json])
fpath = os.path.expanduser(f~/.openclaw/media/edited_{int(time.time())}.png)
with open(fpath, wb) as f:
f.write(img_data)
print(fpath)

从URL编辑:

bash
curl -s https://api.x.ai/v1/images/generations \
-H Authorization: Bearer $XAIAPIKEY \
-H Content-Type: application/json \
--data {
model: grok-imagine-image,
prompt: <编辑提示词>,
image_url: <公开图像URL>,
n: 1,
responseformat: b64json
} | python3 -c
import json, sys, base64, os, time
os.makedirs(os.path.expanduser(~/.openclaw/media), exist_ok=True)
r = json.load(sys.stdin)
imgdata = base64.b64decode(r[data][0][b64json])
fpath = os.path.expanduser(f~/.openclaw/media/edited_{int(time.time())}.png)
with open(fpath, wb) as f:
f.write(img_data)
print(fpath)

风格迁移示例

使用带有风格提示词的编辑功能,例如:

  • - 以印象派风格渲染为油画
  • 制作成带有细致阴影的铅笔素描
  • 转换为色彩大胆的波普艺术
  • 边缘柔和的水彩画

3. 发送到Telegram

消息工具:action=send, channel=telegram, target=,
message=<标题>, filePath=~/.openclaw/media/<文件>.png

  • - 始终包含 message 字段(即使仅发送媒体也需要)
  • 允许的媒体路径:/tmp/、~/.openclaw/media/、~/.openclaw/agents/

注意事项

  • - 请勿传递 size 参数——会返回400错误
  • 宽高比:在JSON请求体中传递 aspectratio(而非 size)
  • 编辑:在生成端点中使用 imageurl 字段(而非使用 multipart 的编辑端点)
  • 始终使用 responseformat: b64json——URL格式会返回临时URL,经常出现403错误
  • 对于大图像:使用Python构建载荷 → 保存到 /tmp/ → 使用 @file 语法调用curl
  • 每次请求最多10张图像
  • 图像需经过内容审核
  • 编辑是风格迁移/重新想象,而非像素级精确修复

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 grok-imagine-image-pro-1776420050 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 grok-imagine-image-pro-1776420050 技能

通过命令行安装

skillhub install grok-imagine-image-pro-1776420050

下载

⬇ 下载 grok-imagine-image-pro v1.0.2(免费)

文件大小: 2.87 KB | 发布时间: 2026-4-17 19:14

v1.0.2 最新 2026-4-17 19:14
Fix: TIMESTAMP bug in Python f-strings. Fix: consistent paths with expanduser. Added editing limitation note.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部