Compresses images to WebP (default) or PNG with automatic tool selection. Use when user asks to "compress image", "optimize image", "convert to webp", or reduce image file size.
git clone https://github.com/JimLiu/baoyu-skills.git--- name: baoyu-compress-image description: Compresses images to WebP (default) or PNG with automatic tool selection. Use when user asks to "compress image", "optimize image", "convert to webp", or reduce image file size. version: 1.56.1 metadata: openclaw: homepage: https://github.com/JimLiu/baoyu-skills#baoyu-compress-image requires: anyBins: - bun - npx --- # Image Compressor Compresses images using best available tool (sips → cwebp → ImageMagick → Sharp). ## Script Directory Scripts in `scripts/` subdirectory. `{baseDir}` = this SKILL.md's directory path. Resolve `${BUN_X}` runtime: if `bun` installed → `bun`; if `npx` available → `npx -y bun`; else suggest installing bun. Replace `{baseDir}` and `${BUN_X}` with actual values. | Script | Purpose | |--------|---------| | `scripts/main.ts` | Image compression CLI | ## Preferences (EXTEND.md) Check EXTEND.md in priority order — the first one found wins: | Priority | Path | Scope | |----------|------|-------| | 1 | `.baoyu-skills/baoyu-compress-image/EXTEND.md` | Project | | 2 | `${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-compress-image/EXTEND.md` | XDG | | 3 | `$HOME/.baoyu-skills/baoyu-compress-image/EXTEND.md` | User home | If none found, use defaults. **EXTEND.md supports**: Default format, default quality, keep-original preference. ## Usage ```bash ${BUN_X} {baseDir}/scripts/main.ts <input> [options] ``` ## Options | Option | Short | Description | Default | |--------|-------|-------------|---------| | `<input>` | | File or directory | Required | | `--output` | `-o` | Output path | Same path, new ext | | `--format` | `-f` | webp, png, jpeg | webp | | `--quality` | `-q` | Quality 0-100 | 80 | | `--keep` | `-k` | Keep original | false | | `--recursive` | `-r` | Process subdirs | false | | `--json` | | JSON output | false | ## Examples ```bash # Single file → WebP (replaces original) ${BUN_X} {baseDir}/scripts/main.ts image.png # Keep PNG format ${BUN_X} {baseDir}/scripts/main.ts image.png -f png --keep # Directory recursive ${BUN_X} {baseDir}/scripts/main.ts ./images/ -r -q 75 # JSON output ${BUN_X} {baseDir}/scripts/main.ts image.png --json ``` **Output**: ``` image.png → image.webp (245KB → 89KB, 64% reduction) ``` ## Extension Support Custom configurations via EXTEND.md. See **Preferences** section for paths and supported options.
[{"step":1,"action":"Identify the image you want to compress and its file path. For example, use `~/Pictures/vacation.jpg`.","tip":"For batch processing, list all image paths separated by commas or use a wildcard (e.g., `~/Pictures/*.jpg`)."},{"step":2,"action":"Specify the output path where the compressed image should be saved. If no path is given, save it to the same directory as the original with '_compressed' appended to the filename.","tip":"Use a dedicated folder (e.g., `~/Pictures/optimized/`) to keep compressed images organized."},{"step":3,"action":"Run the compression. The tool will automatically select the best method (WebP for most cases, PNG for transparency or lossless needs).","tip":"For lossless compression, explicitly request PNG format (e.g., 'Compress this PNG image losslessly')."},{"step":4,"action":"Review the output. Check the file size reduction and visual quality. If the result isn’t satisfactory, adjust the quality settings or try a different format.","tip":"Use image viewers like Preview (Mac) or FastStone Image Viewer (Windows) to compare the original and compressed versions side by side."},{"step":5,"action":"If further optimization is needed, specify custom settings like quality level (e.g., 'Compress this image to WebP with 70% quality') or request additional formats.","tip":"For web use, aim for files under 200 KB for faster loading. For print, prioritize quality over size."}]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/JimLiu/baoyu-skills/tree/main/skills/baoyu-compress-imageCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Compress the image at [IMAGE_PATH] to reduce its file size while maintaining visual quality. Use WebP format for the best balance of compression and quality. If the input is in a format other than WebP, convert it to WebP. If the user specifically requests PNG format, output in PNG. Provide the compressed file size in KB or MB and the percentage reduction from the original. Save the compressed image to [OUTPUT_PATH].
The image at `~/Downloads/photo.jpg` (original size: 2.4 MB) has been compressed to WebP format and saved to `~/Downloads/photo_compressed.webp`. The compressed file size is 450 KB, achieving a **81.25% reduction** in file size while preserving high visual quality. The dimensions remain unchanged at 4000x3000 pixels, and no significant quality loss is visible upon inspection. The compression was performed using lossy WebP encoding with a quality setting of 80/100 to balance size and fidelity. If you need further optimization (e.g., even smaller size or lossless PNG), let me know and I can adjust the settings or re-run the compression.
skills-collection
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan