OpenClaw / Claude Code 技能包 - 通过 Chrome DevTools Protocol (CDP) 自动化提刻AI网页版文生图
⚠️ 重要说明: 提刻AI (tikeai.com) 没有 API,只有网页界面。本 skill 通过 Chrome CDP 模拟用户操作,实现自动化图片生成。
- 自动打开提刻AI网页并登录
- 智能选择模型( Nano Banana / Nano Banana 2 / Nano Banana Pro 等)
- 设置出图比例和分辨率
- 输入提示词并自动点击生成按钮
- 等待生成完成并下载图片
┌─────────────────────────────────────────────────────────────────┐
│ OpenClaw / Claude Code (WSL/Server) │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ skill/tikeai-text2image/main.py │ │
│ │ ┌─────────────────────────────────────────────────┐ │ │
│ │ │ ChromeCDP wrapper │ │ │
│ │ │ ┌──────────────┐ CDP Commands ┌─────────────┐ │ │ │
│ │ │ │ cdp-wrapper.sh│ ──────────────> │ Chrome DevTools │ │ │ │
│ │ │ └──────────────┘ └─────────────┘ │ │ │
│ │ └─────────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ ▲ │
│ │ HTTP (localhost:9222) │
└──────────────────────────┼────────────────────────────────────┘
│
┌──────┴──────┐
│ Chrome │
│ (Host/WSL) │
└─────────────┘
本 skill 依赖 OpenClaw 的 Chrome-Cdp Skill
直接把下面地址告诉龙虾机器人安装即可
https://github.com/pasky/chrome-cdp-skill
# macOS
open -a "Google Chrome" --args \
--remote-debugging-port=9222 \
--user-data-dir="/tmp/chrome-remote"# Linux (Ubuntu/Debian)
google-chrome \
--remote-debugging-port=9222 \
--user-data-dir="/tmp/chrome-remote"# Windows (PowerShell)
& "C:\Program Files\Google\Chrome\Application\chrome.exe" `
--remote-debugging-port=9222 `
--user-data-dir="C:\Temp\chrome-remote"创建 Chrome 快捷方式,右键属性,在"目标"栏添加:
--remote-debugging-port=9222 --user-data-dir="C:\Temp\chrome-remote"
- OpenClaw 运行在 WSL2 (Ubuntu)
- Chrome 运行在 Windows 宿主机
- 需要让 WSL 能访问宿主机的 Chrome CDP 端口 (9222)
- 在宿主机 Windows Chrome 启动时绑定到所有接口:
# 使用宿主机IP访问
chrome.exe --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0- 方式一:直接连接宿主机 IP)
获取宿主机 IP (在 WSL 中执行):
# 使用 Windows 默认网关
cat /etc/resolv.conf | grep nameserver | awk '{print $2}'
# 假设输出: 172.28.160.1
# 测试是否能访问宿主机的 9222 端口
curl http://172.28.160.1:9222/json/version- 方式二:使用 netsh 端口转发 (推荐)
如果直接连接有困难,可在 Windows 宿主机配置端口转发:
# 以管理员身份运行 PowerShell
# 将宿主机 9223 端口转发到 9222
netsh interface portproxy add v4tov4 listenport=9223 listenaddress=0.0.0.0 connectport=9222 connectaddress=127.0.0.1
# 测试连接(WSL 中)
curl http://localhost:9223/json/version- 如果连接超时,检查 Windows 防火墙是否允许 9222/9223 端口
- 使用
netsh interface portproxy show v4tov4查看当前转发规则 - 使用
netsh interface portproxy delete v4tov4 listenport=9223删除规则
- 在宿主机 Windows Chrome 启动时绑定到所有接口:
# 使用宿主机IP访问
chrome.exe --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0- 获取宿主机 IP (在 WSL 中执行):
# 方法1: 使用 Windows 默认网关
cat /etc/resolv.conf | grep nameserver | awk '{print $2}'
# 方法2: 使用 hostname
hostname -I- 测试连接 (在 WSL 中):
# 测试是否能访问宿主机的 9222 端口
curl http://172.28.160.1:9222/json/version
# 应该返回类似:
# {
# "Browser": "Chrome/123.0.6312.123",
# "Protocol-Version": "1.3",
# ...
# }- 配置 cdp-wrapper.sh (如果需要指定宿主机 IP):
默认情况下,OpenClaw 的 cdp-wrapper.sh 使用 localhost:9222。如果 Chrome 在宿主机,需要修改 wrapper 脚本中的地址。
# 在 WSL 或服务器上执行
curl http://localhost:9222/json/version
# 如果返回 Chrome 信息,说明配置成功
# 如果连接失败,检查:
# 1. Chrome 是否以 --remote-debugging-port=9222 启动
# 2. 防火墙是否允许 9222 端口
# 3. 如果是 WSL+宿主机,检查网络映射在 OpenClaw 中调用 skill:
# 直接运行脚本
uv run ~/.openclaw/skills/tikeai-text2image/main.py \
--prompt "一只可爱的柴犬在樱花树下微笑" \
--model "Nano Banana 2" \
--ratio "9:16" \
--resolution "2K"언어 Claude Code 中配置 skill 路径:
{
"skills": [
{
"name": "tikeai-text2image",
"path": "~/.openclaw/skills/tikeai-text2image"
}
]
}| 参数 | 说明 | 示例 |
|---|---|---|
--prompt |
图片生成提示词(必填) | "柴犬在樱花树下微笑" |
--model |
选择模型(可选,默认自动选择) | Nano Banana, Nano Banana 2, Nano Banana Pro |
--ratio |
出图比例(可选,默认自动) | 9:16, 16:9, 1:1, 2:3, 3:2, 4:3, 3:4 |
--resolution |
分辨率(可选,默认自动) | 1K, 2K, 4K |
--output-dir |
图片保存目录 | ./outputs |
脚本会自动:
- 读取页面当前选中的模型、比例、分辨率
- 只有当需要修改时才会发送点击操作
- 支持动态识别新增的模型和参数
你只需要在对话中@机器人,然后讲出你想要的图片:
用户: @小牛 出一张柴犬在樱花树下微笑的图片,9:16 比例
小牛:
正在调用 tikeai-text2image skill...
📝 生成参数:
提示词: 柴犬在樱花树下微笑
模型: Nano Banana 2
比例: 9:16
分辨率: 2K
🔄 正在生成...
✅ 图片已生成并发送!
用户: @小牛 出一张赛博朋克夜景,16:9,4K 分辨率
小牛:
正在调用 tikeai-text2image skill...
📝 生成参数:
提示词: 赛博朋克夜景
模型: Nano Banana
比例: 16:9
分辨率: 4K
🔄 正在生成...
✅ 图片已生成并发送!
用户: @小牛 出一张太空站的图片,1:1 比例
小牛:
正在调用 tikeai-text2image skill...
📝 生成参数:
提示词: 太空站
模型: Nano Banana Pro
比例: 1:1
分辨率: 4K
🔄 正在生成...
✅ 图片已生成并发送!
A: 检查 Chrome 是否以 --remote-debugging-port=9222 启动:
# macOS/Linux
ps aux | grep chrome | grep 9222
# Windows (PowerShell)
Get-Process chrome | Where-Object { $_.CommandLine -like "*9222*" }A: 确保你已登录提刻AI账号,或者网页在自动登录模式下运行。
A: 检查提刻AI网页是否已更新,按钮选择器可能需要调整。查看 main.py 中的 click_generate_button() 方法。
A: 脚本通过 DOM 元素文本匹配模型名称。如果提刻AI新增了模型,只需确保模型名称出现在页面上即可自动识别。
欢迎提交 Issue 和 Pull Request!
MIT License
patdelphi