{"skill":{"slug":"ccy-txt2img","displayName":"Ccy Txt2img","summary":"本地离线图片生成技能。支持文本转图片、基础图形绘制（点线面圆等）、颜色填充与描边、简单图片合成，以及基于中文/英文描述的规则驱动智能绘制。仅依赖 Pillow，输出 PNG/JPEG。","description":"---\nname: ccy-txt2img\ndescription: 本地离线图片生成技能。支持文本转图片、基础图形绘制（点线面圆等）、颜色填充与描边、简单图片合成，以及基于中文/英文描述的规则驱动智能绘制。仅依赖 Pillow，输出 PNG/JPEG。\n---\n\n# ccy-txt2img\n\n本技能用于**本地离线生成简单图片**。仅依赖 Pillow，不调用外部 API。\n\n## 什么时候使用\n\n- 把中文/英文文本渲染成 PNG/JPEG\n- 生成简单示意图、海报底图、流程草图、几何图形\n- 根据简单中文/英文描述规则化绘图\n- 用 scene JSON 精确绘制点、线、矩形、圆、文字、图标和图片图层\n\n## 快速路径\n\n技能目录：`skills/ccy-txt2img/`\n\n### 文本转图片\n\n```python\nfrom scripts.txt2img import text_to_image\n\ntext_to_image(\n    \"你好，OpenClaw\\n支持中文换行\",\n    \"output.png\",\n    width=800,\n    height=400,\n    font_size=32,\n    align=\"center\"\n)\n```\n\n### 描述驱动绘图\n\n```python\nfrom scripts.smart_draw import smart_draw\n\nsmart_draw(\n    \"白色背景，一个蓝色圆，一个红色矩形，一条黑线，写上：你好，开发点点\",\n    \"smart.png\"\n)\n```\n\n也可以直接走 CLI：\n\n```bash\npython3 skills/ccy-txt2img/scripts/smart_draw.py \\\n  --prompt \"现代办公室场景，有办公桌、电脑和椅子，写上：Factory Office\" \\\n  --out office.png \\\n  --width 900 --height 600\n```\n\n渲染 scene JSON：\n\n```bash\npython3 skills/ccy-txt2img/scripts/smart_draw.py --scene scene.json --out scene.png\n```\n\n如需查看 prompt 解析出的 scene：加 `--print-scene`。\n\n### scene 精确绘制\n\n```python\nfrom scripts.smart_draw import render_scene\n\nscene = {\n    \"canvas\": {\"width\": 800, \"height\": 600, \"background\": \"#ffffff\"},\n    \"layers\": [\n        {\"type\": \"rect\", \"x\": 60, \"y\": 60, \"w\": 200, \"h\": 120, \"fill\": \"#E6F4FF\", \"stroke\": \"#1677ff\", \"stroke_width\": 3},\n        {\"type\": \"circle\", \"cx\": 420, \"cy\": 140, \"r\": 70, \"fill\": \"#FFF1F0\", \"stroke\": \"#ff4d4f\", \"stroke_width\": 3},\n        {\"type\": \"text\", \"text\": \"中英文字测试 Hello\", \"x\": 60, \"y\": 260, \"w\": 680, \"h\": 120, \"font_size\": 30, \"color\": \"#111111\"}\n    ],\n    \"output\": {\"path\": \"scene.jpg\", \"format\": \"JPEG\"}\n}\n\nrender_scene(scene)\n```\n\n## 能力边界\n\n- 这是规则/程序化绘图，不是 Stable Diffusion / DALL·E 类真实图片生成。\n- 适合简洁、可控、低成本的示意图和文字图。\n- 自然语言理解基于关键词，复杂构图建议直接使用 scene JSON。\n\n## 主要脚本\n\n- `scripts/txt2img.py`\n  - `text_to_image(...)`：保存文字图片\n  - `render_text_image(...)`：内存渲染文字图层\n  - `create_code_image(...)`：生成简易代码截图风格图片\n- `scripts/smart_draw.py`\n  - `smart_draw(...)`：描述转图片\n  - `parse_description(...)`：描述转 scene\n  - `render_scene(...)`：scene 渲染\n  - CLI：`--prompt/--scene --out`，支持 `--width --height --background --print-scene`\n- `examples.py`：示例脚本\n\n## 验证\n\n```bash\npython3 -m compileall -q skills/ccy-txt2img/scripts\npython3 skills/ccy-txt2img/examples.py\n```\n\n## 实用建议\n\n- 中文文本优先使用系统 NotoSansCJK / 文泉驿字体；也可传 `font_path`。\n- JPEG 不支持透明背景；需要透明时输出 PNG。\n- 批量/并发生成时可以放心使用 `smart_draw`，文字图层在内存渲染，不再依赖固定临时文件。\n","tags":{"latest":"1.0.1"},"stats":{"comments":0,"downloads":328,"installsAllTime":0,"installsCurrent":0,"stars":0,"versions":1},"createdAt":1778115975837,"updatedAt":1778492864292},"latestVersion":{"version":"1.0.1","createdAt":1778115975837,"changelog":"- Initial public release of ccy-txt2img: an offline image generation skill using only Pillow.\n- Supports text-to-image, basic shapes (point, line, rectangle, circle), color fill and stroke, and simple image composition.\n- Enables rule-driven drawing via Chinese/English descriptions for quick visualizations.\n- Accepts scene JSON for precise rendering of shapes, layers, and text.\n- Provides both Python API and CLI usage.\n- Optimized for simple diagrams, text posters, and controllable graphics—ideal for non-photorealistic and low-cost images.","license":"MIT-0"},"metadata":null,"owner":{"handle":"chenchongyong","userId":"s1702t2wqma6ghbsampqdvkaw58518za","displayName":"超控中国","image":"https://avatars.githubusercontent.com/u/57010759?v=4"},"moderation":null}