image-compress-skill

A production-grade, Rust-powered image optimization engine for AI Agents. Smartly routes between PNG quantization and WebP compression.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "image-compress-skill" with this command: npx skills add 994ak/image-compress-skill/994ak-image-compress-skill-image-compress-skill

ImageCompressSkill

The intelligent image optimization engine for AI Agents. Smart routing between PNG quantization and WebP compression.

1. Smart Strategy Overview

The optimal compression strategy depends on the input content type and the target use case.

Content TypePrimary StrategyToolchainTarget Format
PhotographsLossy WebPimage -> libwebp.webp
Graphics / Logos / UIOptimized PNGimage -> imagequant -> oxipng.png
Universal (Web)WebP (High Compat)image -> libwebp.webp
Universal (Archive)Optimized PNGimage -> oxipng (Lossless).png

Decision Logic:

  1. Try WebP First (Default): For most web use cases, WebP offers the best size/quality ratio (30-90% reduction).
  2. Fallback to PNG: If the input is a simple graphic (low color count) OR if WebP results in a larger file (rare, but happens with simple shapes), use the Quantized PNG pipeline.
  3. Strict Quality: If the user demands "Lossless" or "No visual change", skip quantization and use only oxipng (PNG) or Lossless WebP.

Setup

This skill requires the image-compress-tool binary.

If the tool is not found, the agent should run:

./scripts/install.sh

Usage

1. Smart Compression (Auto)

Best for: Photos, complex gradients, web assets.

  • Quality (-q):
    • 80-85: Sweet spot for web (visually indistinguishable). Default.
    • 75: Aggressive, might show slight artifacts on sharp edges.
    • 90+: Archival quality, diminishing returns.
  • Method (-m):
    • 4: Default. Good balance.
    • 6: Slowest but best compression. Use for static assets (build time).
  • Usage:
    // Rust (using webp crate)
    let encoder = webp::Encoder::from_image(&img)?;
    let memory = encoder.encode(80.0); // Q=80
    

B. Optimized PNG (via imagequant + oxipng)

Best for: Logos, icons, screenshots, line art, transparent assets.

  • Step 1: Quantization (imagequant)
    • Quality: min=0, max=80 (or 80-90 for high fidelity).
    • Speed: 4 (Default). 1 (Slowest/Best).
    • Note: This step converts 32-bit RGBA to 8-bit Indexed Color. It is "lossy" but visually excellent for graphics.
  • Step 2: Optimization (oxipng)
    • Level (-o):
      • 2: Default. Good balance.
      • 4: Recommended for production builds (slower but worth it).
      • 6: Max. Very slow.
    • Strip (--strip safe): Remove metadata.
    • Interlace (-i 0): Disable interlacing (saves ~20%).
  • Usage:
    // Pipeline
    let (palette, pixels) = imagequant_attributes.quantize(img)?; // Step 1
    let png_data = encode_png(palette, pixels);
    let optimized = oxipng::optimize_from_memory(&png_data, &options)?; // Step 2
    

3. Implementation Rules for Agents

When implementing image compression tools:

  1. Dual Mode Support: Always implement BOTH pipelines (WebP and PNG).
  2. Smart Defaults:
    • Default Quality: 80 (for both WebP and ImageQuant).
    • Default WebP Method: 4.
    • Default Oxipng Level: 2 (or 4 if speed isn't critical).
  3. Output Logic:
    • If user asks for "compress this image" -> Output WebP (smallest).
    • If user asks for "optimize this PNG" -> Output Quantized PNG.
    • If input is small (< 10KB) simple shape -> Check if WebP > PNG, if so, prefer PNG.

4. Code Resources

Dependency Setup

[dependencies]
image = "0.25"
imagequant = "4.4"
oxipng = "10.1"
webp = "0.3"
anyhow = "1.0"
clap = { version = "4.5", features = ["derive"] }

Rust Implementation Snippet (The "Golden Path")

See image-compress-tool/src/main.rs in the current project for the reference implementation that handles:

  1. CLI Argument Parsing
  2. Image Loading
  3. WebP Branch (using webp crate)
  4. PNG Branch (using imagequant -> png encoding -> oxipng)

5. Verification

Always verify:

  1. File Size: Is output < input?
  2. Format: Is it a valid WebP/PNG?
  3. Visual: Open in browser/viewer.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

clinic-visit-prep

帮助患者整理就诊前问题、既往记录、检查清单与时间线,不提供诊断。;use for healthcare, intake, prep workflows;do not use for 给诊断结论, 替代医生意见.

Archived SourceRecently Updated
Automation

changelog-curator

从变更记录、提交摘要或发布说明中整理对外 changelog,并区分用户价值与内部改动。;use for changelog, release-notes, docs workflows;do not use for 捏造未发布功能, 替代正式合规审批.

Archived SourceRecently Updated
Automation

klaviyo

Klaviyo API integration with managed OAuth. Access profiles, lists, segments, campaigns, flows, events, metrics, templates, catalogs, and webhooks. Use this skill when users want to manage email marketing, customer data, or integrate with Klaviyo workflows. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).

Archived SourceRecently Updated
Automation

lifelog

生活记录自动化系统。自动识别消息中的日期(今天/昨天/前天/具体日期),使用 SubAgent 智能判断,记录到 Notion 对应日期,支持补录标记。 适用于:(1) 用户分享日常生活点滴时自动记录;(2) 定时自动汇总分析并填充情绪、事件、位置、人员字段

Archived SourceRecently Updated