From fa094af8f3a066d77a1357a71ad7dec870e01de6 Mon Sep 17 00:00:00 2001 From: ATRI Date: Tue, 28 Apr 2026 21:49:39 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=84=20=E6=9B=B4=E6=96=B0=E9=95=BF?= =?UTF-8?q?=E6=96=87=E6=9C=ACskill=EF=BC=9A=E6=B7=BB=E5=8A=A0T2I=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../skills/atri_long_text_output.md | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/ATRI My Dear Moments/skills/atri_long_text_output.md b/ATRI My Dear Moments/skills/atri_long_text_output.md index 57ef35a..46d8232 100644 --- a/ATRI My Dear Moments/skills/atri_long_text_output.md +++ b/ATRI My Dear Moments/skills/atri_long_text_output.md @@ -93,14 +93,44 @@ curl -X POST "http://服务器IP:8999/text2img/generate" \\ | 代码 | `代码` | | 引用 | `
引用
` | -### Step 4: 发送图片 +### Step 4: 下载图片并发送到QQ ```python -# 使用send_message_to_user发送图片 +# 通过Docker网关IP下载图片到容器本地 +import urllib.request +T2I_HOST = "172.17.0.1" # Docker网关IP +T2I_PORT = 8999 + +# 调用T2I渲染(调用/text2img/generate获取img_id) +# ... + +# 下载生成的图片到本地 +from datetime import datetime +timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") +img_url = f"http://{T2I_HOST}:{T2I_PORT}/text2img/data/{img_id}" + +with urllib.request.urlopen(img_url, timeout=30) as resp: + img_data = resp.read() + +local_path = f"/AstrBot/data/temp/t2i_render_{timestamp}.png" +with open(local_path, 'wb') as f: + f.write(img_data) + +# 通过QQ发送本地图片 send_message_to_user(messages=[{ "type": "image", - "path": "", # 本地路径 - "url": "http://服务器IP:8999/data/xxx.png" # T2I返回的URL + "path": local_path +}]) +``` + +### 备用:直接发送图片URL + +如果NapCat能访问T2I服务(同一台服务器),也可以用URL: + +```python +send_message_to_user(messages=[{ + "type": "image", + "url": f"http://服务器IP:{T2I_PORT}/text2img/data/{img_id}" }]) ```