994ak/image-compress-skill
Overview
This skill is a production-grade, Rust-powered image optimization engine for AI agents that smartly routes between PNG quantization and WebP compression. It picks the best pipeline based on image content and the target use case to minimize size while preserving visual fidelity. Defaults are tuned for web delivery but support strict lossless or archival needs.
How this skill works
The engine implements two pipelines: a lossy WebP path for photographs and general web assets, and a quantized PNG path (imagequant + oxipng) for logos, icons, and transparency-heavy graphics. Default behavior is to try WebP first and fall back to quantized PNG when WebP increases size or when input is a low-color graphic. Agents can also force lossless or PNG-only modes.
When to use it
- Compress photos, hero images, and gradients for web delivery — use WebP (default).
- Optimize logos, icons, screenshots, or transparent assets — use quantized PNG (imagequant -> oxipng).
- Archive assets where lossless fidelity is required — use oxipng lossless or lossless WebP.
- Batch asset pipelines during builds where slower higher-compression methods are acceptable.
- When file size matters more than encode speed (use higher method/level).
Best practices
- Keep default quality at 80 for a good size/quality balance; increase to 90+ only for archival needs.
- Use WebP method 4 by default; use method 6 for offline build steps where compression time is acceptable.
- For PNGs, run imagequant first (convert to 8-bit indexed) then optimize with oxipng level 2–4; level 4 for production builds.
- Implement dual-mode support in agents: always include both WebP and PNG pipelines and choose based on content.
- Verify outputs: confirm file is smaller, valid, and visually acceptable before replacing originals.
Example use cases
- Auto-compressing a user-uploaded photo gallery for a web app to reduce CDN costs.
- Optimizing a design system asset pipeline where icons and logos must remain crisp and transparent.
- Building a static site asset step that aggressively compresses images at deploy time (method=6, oxipng -o 4).
- Converting mixed-format input batch to optimal formats for archival vs web distribution.
- Agent workflow: if user requests 'optimize this PNG', run PNG pipeline; if 'compress image', prefer WebP.
FAQ
It tries WebP first for most web use cases and falls back to quantized PNG when WebP yields larger files or for low-color graphics.
How do I force lossless output?
Request lossless or high-fidelity mode; the tool will skip quantization and use oxipng lossless or lossless WebP as requested.