Skip to content

patdelphi/tikeai-text2image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tikeai-text2image Skill

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)  │
                    └─────────────┘

前置环境配置

1. 配置 OpenClaw (Claude Code配置方法一样)

本 skill 依赖 OpenClaw 的 Chrome-Cdp Skill

直接把下面地址告诉龙虾机器人安装即可

https://github.com/pasky/chrome-cdp-skill

2. 配置 Chrome 远程调试

方式一:Chrome 启动时添加参数

# 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"

3. WSL + 宿主机 Chrome 网络配置

场景描述

  • OpenClaw 运行在 WSL2 (Ubuntu)
  • Chrome 运行在 Windows 宿主机
  • 需要让 WSL 能访问宿主机的 Chrome CDP 端口 (9222)

配置步骤

  1. 在宿主机 Windows Chrome 启动时绑定到所有接口:
# 使用宿主机IP访问
chrome.exe --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0
  1. 方式一:直接连接宿主机 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
  1. 方式二:使用 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 删除规则

常见问题

配置步骤

  1. 在宿主机 Windows Chrome 启动时绑定到所有接口:
# 使用宿主机IP访问
chrome.exe --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0
  1. 获取宿主机 IP (在 WSL 中执行):
# 方法1: 使用 Windows 默认网关
cat /etc/resolv.conf | grep nameserver | awk '{print $2}'

# 方法2: 使用 hostname
hostname -I
  1. 测试连接 (在 WSL 中):
# 测试是否能访问宿主机的 9222 端口
curl http://172.28.160.1:9222/json/version

# 应该返回类似:
# {
#   "Browser": "Chrome/123.0.6312.123",
#   "Protocol-Version": "1.3",
#   ...
# }
  1. 配置 cdp-wrapper.sh (如果需要指定宿主机 IP):

默认情况下,OpenClaw 的 cdp-wrapper.sh 使用 localhost:9222。如果 Chrome 在宿主机,需要修改 wrapper 脚本中的地址。

4. 验证 Chrome CDP 是否正常

# 在 WSL 或服务器上执行
curl http://localhost:9222/json/version

# 如果返回 Chrome 信息,说明配置成功
# 如果连接失败,检查:
# 1. Chrome 是否以 --remote-debugging-port=9222 启动
# 2. 防火墙是否允许 9222 端口
# 3. 如果是 WSL+宿主机,检查网络映射

使用方法

OpenClaw 中使用

在 OpenClaw 中调用 skill:

# 直接运行脚本
uv run ~/.openclaw/skills/tikeai-text2image/main.py \
  --prompt "一只可爱的柴犬在樱花树下微笑" \
  --model "Nano Banana 2" \
  --ratio "9:16" \
  --resolution "2K"

Claude Code 中使用

언어 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

智能参数识别

脚本会自动:

  1. 读取页面当前选中的模型、比例、分辨率
  2. 只有当需要修改时才会发送点击操作
  3. 支持动态识别新增的模型和参数

调用方式

OpenClaw 机器人对话中直接调用

你只需要在对话中@机器人,然后讲出你想要的图片:


用户: @小牛 出一张柴犬在樱花树下微笑的图片,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

🔄 正在生成...
✅ 图片已生成并发送!

常见问题

Q1: Chrome 已启动但连接不上

A: 检查 Chrome 是否以 --remote-debugging-port=9222 启动:

# macOS/Linux
ps aux | grep chrome | grep 9222

# Windows (PowerShell)
Get-Process chrome | Where-Object { $_.CommandLine -like "*9222*" }

Q2: 提刻AI网页打不开

A: 确保你已登录提刻AI账号,或者网页在自动登录模式下运行。

Q3: 生成按钮点击无效

A: 检查提刻AI网页是否已更新,按钮选择器可能需要调整。查看 main.py 中的 click_generate_button() 方法。

Q4: 如何添加新模型支持?

A: 脚本通过 DOM 元素文本匹配模型名称。如果提刻AI新增了模型,只需确保模型名称出现在页面上即可自动识别。

贡献

欢迎提交 Issue 和 Pull Request!

许可证

MIT License

作者

patdelphi

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages