关于 canghe-compress-image
用于压缩图像文件或目录的 Skill 和命令行工具,会从 sips、cwebp、ImageMagick、Sharp 等工具中选择可用方案。支持设置输出格式、质量及是否保留原文件。
主要功能
- 01压缩文件或目录
- 02选择 WebP、PNG 或 JPEG 格式
- 03设置压缩质量
- 04递归处理子目录
- 05通过 EXTEND.md 设置默认值
适用场景
- 01将图像转换为 WebP
- 02压缩图像文件夹
- 03保留原文件并生成压缩副本
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ freestylefly/ canghe-skills --skill canghe-compress-image安装后在 Claude Code 中输入/canghe-compress-image确认已加载。
附带文件scripts/main.ts
详细介绍
图像压缩器
使用当前最佳工具压缩图像(sips → cwebp → ImageMagick → Sharp)。
脚本目录
脚本位于 scripts/ 子目录中。将 ${SKILL_DIR} 替换为此 SKILL.md 所在的目录路径。
| 脚本 | 用途 |
|---|---|
scripts/main.ts | 图像压缩 CLI |
偏好设置(EXTEND.md)
使用 Bash 按优先级顺序检查是否存在 EXTEND.md:
# Check project-level first
test -f .canghe-skills/canghe-compress-image/EXTEND.md && echo "project"
# Then user-level (cross-platform: $HOME works on macOS/Linux/WSL)
test -f "$HOME/.canghe-skills/canghe-compress-image/EXTEND.md" && echo "user"
┌────────────────────────────────────────────────────────┬───────────────────┐ │ 路径 │ 位置 │ ├────────────────────────────────────────────────────────┼───────────────────┤ │ .canghe-skills/canghe-compress-image/EXTEND.md │ 项目目录 │ ├────────────────────────────────────────────────────────┼───────────────────┤ │ $HOME/.canghe-skills/canghe-compress-image/EXTEND.md │ 用户主目录 │ └────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐ │ 结果 │ 操作 │ ├───────────┼───────────────────────────────────────────────────────────────────────────┤ │ 找到 │ 读取、解析并应用设置 │ ├───────────┼───────────────────────────────────────────────────────────────────────────┤ │ 未找到 │ 使用默认值 │ └───────────┴───────────────────────────────────────────────────────────────────────────┘
EXTEND.md 支持:默认格式 | 默认质量 | 是否保留原图
用法
npx -y bun ${SKILL_DIR}/scripts/main.ts <input> [options]
选项
| 选项 | 短选项 | 描述 | 默认值 |
|---|---|---|---|
<input> | 文件或目录 | 必需 | |
--output | -o | 输出路径 | 相同路径,新扩展名 |
--format | -f | webp、png、jpeg | webp |
--quality | -q | 质量 0-100 | 80 |
--keep | -k | 保留原图 | false |
--recursive | -r | 处理子目录 | false |
--json | JSON 输出 | false |
示例
# Single file → WebP (replaces original)
npx -y bun ${SKILL_DIR}/scripts/main.ts image.png
# Keep PNG format
npx -y bun ${SKILL_DIR}/scripts/main.ts image.png -f png --keep
# Directory recursive
npx -y bun ${SKILL_DIR}/scripts/main.ts ./images/ -r -q 75
# JSON output
npx -y bun ${SKILL_DIR}/scripts/main.ts image.png --json
输出:
image.png → image.webp (245KB → 89KB, 64% reduction)
扩展支持
通过 EXTEND.md 使用自定义配置。路径和支持的选项请参阅偏好设置部分。