cryosnap
面向 CLI / Rust library / Node & TypeScript 绑定的代码与终端输出截图工具。 | Code and terminal screenshot tool for CLI / Rust library / Node & TypeScript bindings.
中文
功能概览
- 代码高亮(syntect 主题)
- ANSI 终端输出解析(含
--executePTY) - SVG / PNG / WebP 输出
- PNG 无损优化(oxipng)
- PNG 有损量化(libimagequant,可选,支持预设)
- 可选多输出:
out.{svg,png,webp} - 交互式配置(
--interactive) - 配置文件:
default / base / full / user / 自定义路径 - 字体嵌入(TTF/WOFF/WOFF2)
- Nerd Font 符号回退(按需自动下载,可配置)
- 标题栏(自动文件路径 / tmux 信息)
- 栅格化后端:纯 Rust / rsvg-convert(自动检测)
- 细节配置:padding/margin/border/shadow/line-height/lines/wrap/line-numbers
安装
crates.io 安装(推荐):
# CLI
# Rust 库
源码安装:
# 或
CLI 使用
# 代码文件 -> PNG
# stdin -> SVG
|
# ANSI 命令输出
# 一次生成多种格式
# tmux capture-pane -> PNG (zsh 需转义 %)
默认行为:stdout 为 TTY 且未指定 --output/--format 时,会写入 cryosnap.png。
查看完整参数:
配置
内置配置:
配置文件路径优先级:
CRYOSNAP_CONFIG_PATHCRYOSNAP_CONFIG_DIR(会读取user.json)- 系统配置目录(
ProjectDirs)
PNG 压缩
默认使用无损优化(不会影响画质):
# 关闭无损优化
# 调整优化级别(0-6)
# 控制元数据剥离
有损量化(体积更小,轻微画质损失):
# 开启量化
# 使用预设(fast/balanced/best)
# 自定义质量/速度/抖动
栅格化后端
默认使用纯 Rust 渲染(resvg/tiny-skia)。如系统已安装 rsvg-convert,可选用:
# 自动检测(找到 rsvg-convert 则使用)
# 强制使用 rsvg-convert(未安装会报错)
# 强制使用纯 Rust
字体与 Nerd Font
默认字体为系统 monospace,不再内置任何字体。
当输入包含非 ASCII 脚本、Emoji、或 Nerd Font 私用区字符时,会按 Unicode Script
自动匹配 Noto 系列字体;若系统字体已覆盖则不下载,否则从 GitHub 官方仓库
自动下载到 ~/.cryosnap/fonts(可用 font.dirs 或 CRYOSNAP_FONT_DIRS 覆盖),随后渲染。
可用 font.fallbacks 指定回退链,font.system-fallback 控制系统字体加载
(auto/always/never),font.auto-download 控制自动下载;
font.cjk-region 指定 CJK 偏好(auto/sc/tc/hk/jp/kr,auto 会按 LANG/LC_CTYPE 推断);
font.force-update 可强制刷新已下载字体:
# 自动下载缺失字体(默认开启)
# Nerd Font + 中文回退
# 指定 CJK 偏好
# 禁用自动下载
# 强制刷新已下载字体
标题栏
默认启用,文件输入时显示绝对路径;tmux 模式显示:
#{session_name}:#{window_index}.#{pane_index} #{pane_title}。
# 关闭标题
# 覆盖标题文本
# tmux 标题格式(自定义)
性能建议
# 降低栅格缩放
# 限制最大像素数(0 表示不限制)
# 如需极致速度可关闭 PNG 优化
Rust 库用法
use ;
let request = RenderRequest ;
let result = render.unwrap;
write.unwrap;
Node / TypeScript 绑定
发布版(npm):
import { render, renderToFile } from "cryosnap";
const bytes = render({
input: "console.log('hi')",
inputKind: "text",
config: {
theme: "charm",
window: true,
showLineNumbers: true,
padding: [20, 40, 20, 20],
lineHeight: 1.2
},
format: "png"
});
require("fs").writeFileSync("out.png", bytes);
renderToFile(
{
input: "console.log('hi')",
inputKind: "text",
config: { theme: "charm" }
},
"out.webp"
);
开发与测试
发布流程(cargo-release + cargo-dist)
# 预演
# 执行(会创建 tag vX.Y.Z)
# tag 会触发 GitHub Actions 的 cargo-dist 发布产物
crates.io 发布顺序:
npm 发布:
许可证
MIT,详见 LICENSE。
第三方许可证
- Noto 字体(含 CJK/多脚本/Emoji):SIL Open Font License 1.1(自动下载,来源 GitHub)
- Nerd Font(Symbols Nerd Font Mono):MIT(自动下载,来源 GitHub)
English
Overview
- Syntax highlighting (syntect themes)
- ANSI terminal capture (with
--executePTY) - SVG / PNG / WebP output
- PNG lossless optimization (oxipng)
- PNG lossy quantization (libimagequant, optional, with presets)
- Multi-output pattern:
out.{svg,png,webp} - Interactive config (
--interactive) - Config files:
default / base / full / user / custom - Font embedding (TTF/WOFF/WOFF2)
- Nerd Font symbol fallback (auto-download, configurable)
- Title bar (auto file path / tmux metadata)
- Raster backends: pure Rust / rsvg-convert (auto-detect)
- Detailed styling: padding/margin/border/shadow/line-height/lines/wrap/line-numbers
Install
From crates.io (recommended):
From source:
# or
CLI Usage
# File -> PNG
# stdin -> SVG
|
# ANSI command output
# Multi-format output
# tmux capture-pane -> PNG (escape % in zsh)
Default behavior: when stdout is a TTY and --output/--format is not provided, it writes cryosnap.png.
Show all options:
Configuration
Built-in configs:
Config path priority:
CRYOSNAP_CONFIG_PATHCRYOSNAP_CONFIG_DIR(readsuser.json)- System config directory (
ProjectDirs)
PNG Optimization
Lossless optimization (no quality loss):
# Disable lossless optimization
# Optimize level (0-6)
# Metadata stripping
Lossy quantization (smaller size with slight quality loss):
# Enable quantization
# Preset (fast/balanced/best)
# Custom quality/speed/dither
Raster Backend
Default uses pure Rust (resvg/tiny-skia). If rsvg-convert is available, you can opt in:
Fonts & Nerd Font
Default font is system monospace, and no fonts are embedded.
When input contains non-ASCII scripts, emoji, or Nerd Font private-use glyphs, cryosnap
auto-maps to Noto families by Unicode Script. If system fonts already cover them it will not
download; otherwise it downloads from GitHub official repos into ~/.cryosnap/fonts
(override via font.dirs or CRYOSNAP_FONT_DIRS).
Use font.fallbacks to set a fallback chain, font.system-fallback for system font loading
(auto/always/never), font.auto-download to control auto download,
font.cjk-region to set CJK preference (auto/sc/tc/hk/jp/kr, auto uses LANG/LC_CTYPE),
and font.force-update to force refreshing downloaded fonts:
# Auto-download missing fonts (default on)
# Nerd Font + CJK fallback
# Set CJK preference
# Disable auto-download
# Force refresh downloaded fonts
Title Bar
Enabled by default. For file input it shows the absolute path; for tmux it shows:
#{session_name}:#{window_index}.#{pane_index} #{pane_title}.
# Disable title
# Override title text
# Custom tmux title format
Performance Tips
# Lower raster scale
# Limit max pixels (0 = no limit)
# Disable PNG optimization for max speed
Rust Library Usage
use ;
let request = RenderRequest ;
let result = render.unwrap;
write.unwrap;
Node / TypeScript Bindings
Published version (npm):
import { render, renderToFile } from "cryosnap";
const bytes = render({
input: "console.log('hi')",
inputKind: "text",
config: {
theme: "charm",
window: true,
showLineNumbers: true,
padding: [20, 40, 20, 20],
lineHeight: 1.2
},
format: "png"
});
require("fs").writeFileSync("out.png", bytes);
renderToFile(
{
input: "console.log('hi')",
inputKind: "text",
config: { theme: "charm" }
},
"out.webp"
);
Development & Testing
Release Flow
Pushing the tag will trigger GitHub Actions to publish cargo-dist artifacts.
Publish to crates.io:
Publish to npm:
License
MIT, see LICENSE.
Third-party Licenses
- Noto fonts (including CJK/multi-script/emoji): SIL Open Font License 1.1 (auto-downloaded from GitHub)
- Nerd Font (Symbols Nerd Font Mono): MIT (auto-downloaded from GitHub)