Skip to content

feat: 支持 text2img 命令(文字生成图片) - #70

Open
bee1an wants to merge 1 commit into
jackwener:mainfrom
bee1an:feat/text2img
Open

feat: 支持 text2img 命令(文字生成图片)#70
bee1an wants to merge 1 commit into
jackwener:mainfrom
bee1an:feat/text2img

Conversation

@bee1an

@bee1an bee1an commented Jul 6, 2026

Copy link
Copy Markdown

概述

新增 xhs text2img 命令,调用小红书 text2imgv3 接口,根据文字生成多风格封面图片。

Closes #69

改动

  • xhs_cli/client_mixins.py: 新增 text2img() 方法,复用 _creator_post + _search_request_id,自动接入反风控(限速/重试/验证码冷却)
  • xhs_cli/commands/creator.py: 新增 text2img 命令 + _download_images 辅助函数
  • xhs_cli/cli.py: 注册命令

用法

# 打印各风格图片 URL
xhs text2img --text "你的文字"

# 下载到本地目录
xhs text2img --text "你的文字" --download ./out/

# 翻页获取更多风格
xhs text2img --text "你的文字" --page 2

安全

  • --download 文件名做 slug 化 + resolve 校验,防止 ../ 路径遍历
  • 下载失败非零退出,不静默成功

测试

  • ruff check . 通过
  • pytest 114 passed, 27 skipped, 0 failed
  • 实际调用验证:返回 10 个风格图片(基础/弥散/美漫/插图/简约/光影/涂写/书摘/涂鸦/备忘)

Call text2imgv3 API to generate multi-style cover images from text.

- Add client.text2img() method, reuse _creator_post and _search_request_id
- Add xhs text2img command with --text/--page/--download options
- Slugify download filenames + path validation, non-zero exit on download failure

Closes jackwener#69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

支持文字生成图片(text2img)命令

1 participant