svg-to-image
将 SVG 转换为 PNG 或 JPG,以便快速共享(例如 Telegram)或打印。
安装 / 下载方式
TotalClaw CLI推荐
totalclaw install totalclaw:totalclaw~qrost-svg-to-imagecURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~qrost-svg-to-image/file -o qrost-svg-to-image.md# SVG to Image Convert SVG files to PNG or JPG. Useful when you have vector graphics (e.g. from map-grabber, diagrams, or design tools) and need a raster image to send in chat or use in documents. ## Dependencies - `cairosvg` (SVG rendering) - `Pillow` (only for JPG output) **Setup:** OpenClaw does not install Python packages automatically. After installing this skill, run once: `pip install -r requirements.txt` (from the skill folder). On Linux (e.g. Ubuntu/Debian), install the Cairo library first: `sudo apt install libcairo2`. If a script fails with `ModuleNotFoundError` or a cairo library error, install the missing package or system library. ## Usage ### Convert SVG to PNG or JPG **Parameters:** - `input`: Path to the SVG file. - `-o`, `--output`: Output file path (default: same name as input with .png or .jpg). - `-f`, `--format`: `png` (default) or `jpg`. - `--width`, `--height`: Optional output size in pixels (keeps aspect ratio if only one is set). - `--dpi`: Scale for rasterization (default 96). ```bash # SVG to PNG (default) python3 scripts/convert_svg.py drawing.svg -o drawing.png # SVG to JPG python3 scripts/convert_svg.py drawing.svg -f jpg -o drawing.jpg # Fixed width 800px (height auto) python3 scripts/convert_svg.py map.svg -o map.png --width 800 ``` ## Sending images to Telegram Used from the OpenClaw Telegram conversation. Run the script with `-o <path>.png` or `-o <path>.jpg`, then **send that file** to the user via the OpenClaw message/media tool. **OpenClaw allowed paths:** The message tool only sends files from allowed dirs (`~/.openclaw/media/`, `~/.openclaw/agents/`, or `/tmp`). Use e.g. `-o ~/.openclaw/media/out.png` or `-o /tmp/out.png`; do not use the skill install directory or sending will fail. **Agent behavior:** When the user asks to convert an SVG to PNG or JPG (or "send as image"), **run the script directly** with `exec`: use `convert_svg.py <svg_path> -o <output>.png` (or `-f jpg`) with output path under an allowed dir, then send the generated image. Do not ask for confirmation; execute and return the image. ## Examples **User:** "Convert this SVG to PNG so I can send it in Telegram." **Action:** Run `convert_svg.py <path> -o /tmp/out.png`, then send the PNG to the user. **User:** "Turn map.svg into a JPG, 1200px wide." **Action:** Run with `-f jpg -o /tmp/map.jpg --width 1200`, then send the JPG. --- ## 中文说明 # SVG to Image 将 SVG 文件转换为 PNG 或 JPG。当你拥有矢量图形(例如来自 map-grabber、图表或设计工具)并需要一张光栅图像以在聊天中发送或用于文档时,这会很有用。 ## 依赖 - `cairosvg`(SVG 渲染) - `Pillow`(仅用于 JPG 输出) **安装:** OpenClaw 不会自动安装 Python 包。安装此技能后,运行一次(在技能文件夹中):`pip install -r requirements.txt`。在 Linux(例如 Ubuntu/Debian)上,先安装 Cairo 库:`sudo apt install libcairo2`。如果脚本因 `ModuleNotFoundError` 或 cairo 库错误而失败,请安装缺失的包或系统库。 ## 用法 ### 将 SVG 转换为 PNG 或 JPG **参数:** - `input`:SVG 文件的路径。 - `-o`、`--output`:输出文件路径(默认:与输入同名,扩展名为 .png 或 .jpg)。 - `-f`、`--format`:`png`(默认)或 `jpg`。 - `--width`、`--height`:可选的输出尺寸(像素)(如果仅设置其中一个,则保持纵横比)。 - `--dpi`:光栅化的缩放比例(默认 96)。 ```bash # SVG to PNG (default) python3 scripts/convert_svg.py drawing.svg -o drawing.png # SVG to JPG python3 scripts/convert_svg.py drawing.svg -f jpg -o drawing.jpg # Fixed width 800px (height auto) python3 scripts/convert_svg.py map.svg -o map.png --width 800 ``` ## 将图像发送至 Telegram 从 OpenClaw 的 Telegram 对话中使用。使用 `-o <path>.png` 或 `-o <path>.jpg` 运行脚本,然后通过 OpenClaw 的 message/media 工具将**该文件发送**给用户。 **OpenClaw 允许的路径:** message 工具只能发送来自允许目录(`~/.openclaw/media/`、`~/.openclaw/agents/` 或 `/tmp`)的文件。例如使用 `-o ~/.openclaw/media/out.png` 或 `-o /tmp/out.png`;不要使用技能安装目录,否则发送会失败。 **代理行为:** 当用户要求将 SVG 转换为 PNG 或 JPG(或“作为图像发送”)时,使用 `exec` **直接运行脚本**:使用 `convert_svg.py <svg_path> -o <output>.png`(或 `-f jpg`),输出路径位于某个允许目录下,然后发送生成的图像。不要请求确认;直接执行并返回图像。 ## 示例 **用户:** "Convert this SVG to PNG so I can send it in Telegram." **操作:** 运行 `convert_svg.py <path> -o /tmp/out.png`,然后将 PNG 发送给用户。 **用户:** "Turn map.svg into a JPG, 1200px wide." **操作:** 使用 `-f jpg -o /tmp/map.jpg --width 1200` 运行,然后发送 JPG。