canghe-compress-image
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImage Compressor
图片压缩工具
Compresses images using best available tool (sips → cwebp → ImageMagick → Sharp).
使用最优可用工具压缩图片,工具优先级为:sips → cwebp → ImageMagick → Sharp。
Script Directory
脚本目录
Scripts in subdirectory. Replace with this SKILL.md's directory path.
scripts/${SKILL_DIR}| Script | Purpose |
|---|---|
| Image compression CLI |
脚本位于子目录中。请将替换为当前SKILL.md文件所在的目录路径。
scripts/${SKILL_DIR}| 脚本 | 用途 |
|---|---|
| 图片压缩CLI工具 |
Preferences (EXTEND.md)
偏好设置(EXTEND.md)
Use Bash to check EXTEND.md existence (priority order):
bash
undefined使用Bash脚本检查EXTEND.md文件是否存在(优先级顺序如下):
bash
undefinedCheck project-level first
优先检查项目级配置
test -f .canghe-skills/canghe-compress-image/EXTEND.md && echo "project"
test -f .canghe-skills/canghe-compress-image/EXTEND.md && echo "project"
Then user-level (cross-platform: $HOME works on macOS/Linux/WSL)
然后检查用户级配置(跨平台:$HOME在macOS/Linux/WSL环境下均适用)
test -f "$HOME/.canghe-skills/canghe-compress-image/EXTEND.md" && echo "user"
┌────────────────────────────────────────────────────────┬───────────────────┐
│ Path │ Location │
├────────────────────────────────────────────────────────┼───────────────────┤
│ .canghe-skills/canghe-compress-image/EXTEND.md │ Project directory │
├────────────────────────────────────────────────────────┼───────────────────┤
│ $HOME/.canghe-skills/canghe-compress-image/EXTEND.md │ User home │
└────────────────────────────────────────────────────────┴───────────────────┘
┌───────────┬───────────────────────────────────────────────────────────────────────────┐
│ Result │ Action │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Found │ Read, parse, apply settings │
├───────────┼───────────────────────────────────────────────────────────────────────────┤
│ Not found │ Use defaults │
└───────────┴───────────────────────────────────────────────────────────────────────────┘
**EXTEND.md Supports**: Default format | Default quality | Keep original preferencetest -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支持配置项**:默认格式 | 默认质量 | 是否保留原文件Usage
使用方法
bash
npx -y bun ${SKILL_DIR}/scripts/main.ts <input> [options]bash
npx -y bun ${SKILL_DIR}/scripts/main.ts <input> [options]Options
选项说明
| Option | Short | Description | Default |
|---|---|---|---|
| File or directory | Required | |
| | Output path | Same path, new ext |
| | webp, png, jpeg | webp |
| | Quality 0-100 | 80 |
| | Keep original | false |
| | Process subdirs | false |
| JSON output | false |
| 选项 | 缩写 | 说明 | 默认值 |
|---|---|---|---|
| 文件或目录 | 必填 | |
| | 输出路径 | 原路径,新格式后缀 |
| | webp, png, jpeg | webp |
| | 质量(0-100) | 80 |
| | 保留原文件 | false |
| | 递归处理子目录 | false |
| 输出JSON格式结果 | false |
Examples
示例
bash
undefinedbash
undefinedSingle file → WebP (replaces original)
单文件转换为WebP格式(替换原文件)
npx -y bun ${SKILL_DIR}/scripts/main.ts image.png
npx -y bun ${SKILL_DIR}/scripts/main.ts image.png
Keep PNG format
保留PNG格式并保留原文件
npx -y bun ${SKILL_DIR}/scripts/main.ts image.png -f png --keep
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
npx -y bun ${SKILL_DIR}/scripts/main.ts ./images/ -r -q 75
JSON output
输出JSON格式结果
npx -y bun ${SKILL_DIR}/scripts/main.ts image.png --json
**Output**:image.png → image.webp (245KB → 89KB, 64% reduction)
undefinednpx -y bun ${SKILL_DIR}/scripts/main.ts image.png --json
**输出示例**:image.png → image.webp (245KB → 89KB, 64% reduction)
undefinedExtension Support
扩展支持
Custom configurations via EXTEND.md. See Preferences section for paths and supported options.
可通过EXTEND.md进行自定义配置。有关配置文件路径和支持的选项,请查看「偏好设置」章节。