返回顶部
🇺🇸 English
🇨🇳 简体中文
🇨🇳 繁體中文
🇺🇸 English
🇯🇵 日本語
🇰🇷 한국어
🇫🇷 Français
🇩🇪 Deutsch
🇪🇸 Español
🇷🇺 Русский
t

text-to-image

Render text into an image and return a temporary local image file path, with optional data URI. Use when Clawhub or Codex needs to convert plain text, styled text, colored text, multilingual text, slogans, posters, captions, or text snippets into an image with controllable width, height, format, font size, full-text color, or partial text colors. Support svg, png, jpg, and jpeg output, return a real temp file path under the skill tmp folder, and work across Windows and macOS with built-in font f

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

text-to-image

# Text to Image Use `scripts/render_text_image.py` to generate an image and return a local file path. The script can also include a `data:` image URL when needed. Prefer the script over hand-writing image payloads. The script already handles: - fixed image width and height - output format: `svg`, `png`, `jpg`, `jpeg` - temp file output by default under `tmp/` - absolute and relative file paths in the response - file path, file name, and file size in the response - whole-text color - partial text colors through friendly highlight fields or raw segments - explicit font size - automatic font-size fitting when `font_size` is omitted - newline-aware wrapping - transparent or solid backgrounds - Windows and macOS font fallback ## Input Shape Pass a JSON spec through `--spec-json` or `--spec-file`. Supported fields: ```json { "text": "Hello\nWorld", "highlight_ranges": [ { "start": 0, "end": 5, "color": "#111111" }, { "start": 6, "end": 11, "color": "#ff4d4f" } ], "highlight_texts": [ { "match": "World", "color": "#1677ff", "occurrence": "all", "case_sensitive": true } ], "segments": [ { "text": "Hello ", "color": "#111111" }, { "text": "World", "color": "#ff4d4f" } ], "width": 1200, "height": 630, "format": "png", "font_size": 72, "min_font_size": 12, "default_color": "#111111", "background": "#ffffff", "padding": 48, "line_height": 1.2, "align": "center", "valign": "middle", "font_family": "Microsoft YaHei, PingFang SC, Arial, sans-serif" } ``` Rules: - Provide either `text` or `segments`. If both are present, `segments` wins. - Prefer `text` + `highlight_texts` for simple "make this word red" requests. - Use `highlight_ranges` when the caller knows character positions. - Use `segments` only when the caller already has exact pieces split out. - Keep `\n` when a hard line break is required. - Omit `font_size` to make the script auto-fit the whole text inside the image. - If `font_size` is provided, the script keeps that size and still wraps lines as needed. - `svg` is the default format. - Prefer `png` over `jpg` for text-heavy images. - If `format` is `jpg` or `jpeg`, transparent background is converted to white. Priority: 1. `segments` 2. `text` + `highlight_ranges` / `highlight_texts` 3. `text` only Friendly highlight format: ```json { "text": "ClawHub makes text visible", "highlight_texts": [ { "match": "ClawHub", "color": "#1677ff" }, { "match": "visible", "color": "#fa541c" } ] } ``` Range format: ```json { "text": "Hello World", "highlight_ranges": [ { "start": 6, "end": 11, "color": "#ff4d4f" } ] } ``` ## Recommended Workflow 1. Build the JSON spec from the user's request. 2. Run the script. 3. Return `file_path` to the caller when the next step is file upload. 4. Use `image_url` only when the caller explicitly needs a data URI. Example: ```powershell @' { "segments": [ { "text": "Claw", "color": "#111111" }, { "text": "Hub", "color": "#1677ff" } ], "width": 1024, "height": 512, "format": "png", "background": "#ffffff", "padding": 40 } '@ | Set-Content spec.json python scripts/render_text_image.py --spec-file spec.json --no-data-url ``` ## Output Contract The script prints JSON: ```json { "file_path": "E:\\clawhub\\text-to-image\\tmp\\rendered-0000.png", "relative_file_path": "tmp/rendered-0000.png", "file_name": "rendered-0000.png", "file_size": 21550, "mime_type": "image/png", "format": "png", "width": 1024, "height": 512, "font_size": 96.0, "line_count": 1, "resolved_segments": [ { "text": "Claw", "color": "#111111" }, { "text": "Hub", "color": "#1677ff" } ] } ``` ## Notes - `svg` is lightweight, crisp, and ideal for text rendering. - `png` is the best general-purpose bitmap choice for text images. - `jpg` is supported for compatibility, but it is usually not the best default for text. - Auto-fit uses width-aware wrapping and a font-size search; it is approximate but reliable for mixed Chinese and Latin text. - The script writes files to the skill's own `tmp/` folder by default. - Pass `--output path.ext` to control where the file is written. - Pass `--no-data-url` when the caller only needs upload-ready file metadata. - On macOS the script tries system fonts such as `PingFang` and `STHeiti` before falling back. - On Windows the script tries fonts such as `Microsoft YaHei`, `SimHei`, and `Arial`. - Reusable sample specs live in `testcases/`, including `13-wrap-example.json` for fixed-size wrapping.

标签

skill ai

通过对话安装

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

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 text-to-image-1776126613 技能

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

设置 SkillHub 为我的优先技能安装源,然后帮我安装 text-to-image-1776126613 技能

通过命令行安装

skillhub install text-to-image-1776126613

下载

⬇ 下载 text-to-image v0.1.0(免费)

文件大小: 13.07 KB | 发布时间: 2026-4-15 14:39

v0.1.0 最新 2026-4-15 14:39
Initial release: text-to-image skill with svg/png/jpg output, color highlights, auto-fit sizing, local file paths, and Windows/macOS font fallback.

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

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

p2p_official_large
返回顶部