jpskill.com
🛠️ 開発・MCP コミュニティ

image-compress-skill

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

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-17
取得日時
2026-05-17
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

[Skill 名] image-compress-skill

ImageCompressSkill

AIエージェントのためのインテリジェントな画像最適化エンジンです。PNG量子化とWebP圧縮の間でスマートなルーティングを行います。

1. スマートな戦略の概要

最適な圧縮戦略は、入力コンテンツの種類とターゲットとなるユースケースによって異なります。

コンテンツの種類 主要な戦略 ツールチェーン ターゲット形式
写真 非可逆WebP image -> libwebp .webp
グラフィック / ロゴ / UI 最適化されたPNG image -> imagequant -> oxipng .png
汎用 (Web) WebP (高互換性) image -> libwebp .webp
汎用 (アーカイブ) 最適化されたPNG image -> oxipng (可逆) .png

決定ロジック:

  1. まずWebPを試す (デフォルト): ほとんどのWebユースケースにおいて、WebPは最高のサイズ/品質比を提供します (30-90%の削減)。
  2. PNGへのフォールバック: 入力が単純なグラフィック (低色数) の場合、またはWebPの結果がより大きなファイルになる場合 (まれですが、単純な形状で発生します) は、量子化PNGパイプラインを使用します。
  3. 厳密な品質: ユーザーが「ロスレス」または「視覚的な変更なし」を要求する場合は、量子化をスキップし、oxipng (PNG) またはロスレスWebPのみを使用します。

セットアップ

このスキルには、image-compress-toolバイナリが必要です。

ツールが見つからない場合、エージェントは以下を実行する必要があります。

./scripts/install.sh

使用方法

1. スマート圧縮 (自動)

最適な用途: 写真、複雑なグラデーション、Webアセット。

  • 品質 (-q):
    • 80-85: Webに最適なスイートスポット (視覚的に区別できません)。デフォルト
    • 75: アグレッシブで、シャープなエッジにわずかなアーティファクトが見られる場合があります。
    • 90+: アーカイブ品質で、効果は薄れます。
  • メソッド (-m):
    • 4: デフォルト。良いバランスです。
    • 6: 最も遅いですが、最高の圧縮率です。静的アセット (ビルド時) に使用します。
  • 使用方法:
    // Rust (using webp crate)
    let encoder = webp::Encoder::from_image(&img)?;
    let memory = encoder.encode(80.0); // Q=80

B. 最適化されたPNG (imagequant + oxipng経由)

最適な用途: ロゴ、アイコン、スクリーンショット、線画、透過アセット。

  • ステップ 1: 量子化 (imagequant)
    • 品質: min=0, max=80 (または高忠実度の場合 80-90)。
    • 速度: 4 (デフォルト)。1 (最も遅い/最高)。
    • : このステップは32ビットRGBAを8ビットインデックスカラーに変換します。これは「非可逆」ですが、グラフィックにとっては視覚的に優れています。
  • ステップ 2: 最適化 (oxipng)
    • レベル (-o):
      • 2: デフォルト。良いバランスです。
      • 4: プロダクションビルドに推奨されます (遅いですが、それだけの価値があります)。
      • 6: 最大。非常に遅いです。
    • ストリップ (--strip safe): メタデータを削除します。
    • インターレース (-i 0): インターレースを無効にします (~20%節約)。
  • 使用方法:
    // 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. エージェントの実装ルール

画像圧縮ツールを実装する際:

  1. デュアルモードのサポート: 常に両方のパイプライン (WebPとPNG) を実装してください。
  2. スマートなデフォルト:
    • デフォルト品質: 80 (WebPとImageQuantの両方)。
    • デフォルトWebPメソッド: 4
    • デフォルトOxipngレベル: 2 (または速度が重要でない場合は4)。
  3. 出力ロジック:
    • ユーザーが「この画像を圧縮して」と尋ねた場合 -> WebPを出力します (最小)。
    • ユーザーが「このPNGを最適化して」と尋ねた場合 -> 量子化PNGを出力します。
    • 入力が小さい (< 10KB) 単純な形状の場合 -> WebP > PNGかどうかを確認し、そうであればPNGを優先します。

4. コードリソース

依存関係のセットアップ

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

Rust実装スニペット (「ゴールデンパス」)

CLI引数解析、画像読み込み、WebPブランチ (webpクレートを使用)、PNGブランチ (imagequant -> pngエンコーディング -> oxipng) を処理する参照実装については、現在のプロジェクトのimage-compress-tool/src/main.rsを参照してください。

5. 検証

常に以下を検証してください。

  1. ファイルサイズ: 出力は入力より小さいですか?
  2. 形式: 有効なWebP/PNGですか?
  3. 視覚: ブラウザ/ビューアで開いて確認してください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

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 Type Primary Strategy Toolchain Target Format
Photographs Lossy WebP image -> libwebp .webp
Graphics / Logos / UI Optimized PNG image -> imagequant -> oxipng .png
Universal (Web) WebP (High Compat) image -> libwebp .webp
Universal (Archive) Optimized PNG image -> 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.