Image Compressionのロゴ

Image Compression

コミュニティ
peterbamuhigire
image-compression

Use when implementing or reviewing client image optimisation plus authoritative server decode, validation, resize, metadata stripping, and canonical re-encoding. Use saas-managed-visual-assets for administrative asset lifecycle and frontend-performance for page budgets.

概要

公開者peterbamuhigire
リポジトリchwezi-dev-engine
スキル名image-compression
スター
29
フォーク
6
同梱ファイル
14
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 14個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    peterbamuhigireがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルImage CompressionをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/peterbamuhigire/chwezi-dev-engine/tree/main/skills/frontend-ux/image-compression
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/peterbamuhigire/chwezi-dev-engine.git /tmp/chwezi-dev-engine
mkdir -p .claude/skills
cp -r /tmp/chwezi-dev-engine/skills/frontend-ux/image-compression .claude/skills/image-compression
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでImage Compressionを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にImage Compressionを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Image Compressionは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Platform Notes

  • Optional helper plugins may help in some environments, but they must not be treated as required for this skill.

Image Compression

Acknowledgement: Shared by Peter Bamuhigire, techguypeter.com, +256 784 464178.

Use When

  • Client-side image compression before upload using Squoosh with Canvas fallback and server-side Sharp validation. Use for web apps needing max width 1920px, max size 512KB, transparent UX, and consistent compression stats.

Evidence Produced

CategoryArtifactFormatExample
PerformanceImage compression policyMarkdown doc covering Squoosh client-side targets, Canvas fallback, and Sharp server-side validation budgetsdocs/images/compression-policy.md

References

  • Use the references/ directory for deep detail after reading the core workflow below.

Use a hybrid image-compression path:

  • Client primary: Squoosh (WASM)
  • Client fallback: Canvas API
  • Server safety net: Sharp

Common defaults: 1920 px long-edge envelope, 512 KB canonical output maximum, quality 75 (adjust down inside an explicit quality floor). Product profiles override these values when the rendering context, transparency, or small-scale legibility requires it.

When to Use

✅ Web apps that upload user images and must reduce bandwidth ✅ Need transparent UX (no user action) ✅ Want modern codecs but must support older browsers

When Not to Use

❌ Server-only batch pipelines (use Sharp directly) ❌ Large-scale media processing with complex transforms (use ImageMagick/FFmpeg)

Core Rules

  1. Maintain aspect ratio; never upscale.
  2. Target max width $1920$px and max size $512$ KB.
  3. Start at quality $75$; reduce in steps to meet size.
  4. Prefer JPEG for compatibility; try WebP if size remains too large.
  5. Log compression stats (ratio, saved, processing time).
  6. Treat client MIME, extension, dimensions, and compressed bytes as untrusted hints.
  7. On the server, detect content from bytes, constrain dimensions/pixels/resources, fully decode, strip metadata, and re-encode to a canonical allow-listed raster format.
  8. Preserve alpha for logos/favicons; never force transparent artwork through JPEG.
  9. Store canonical output under an opaque random key outside a public web root, then publish only through an authorized delivery policy.

Decision Flow

  1. Client attempt (Squoosh)
    • Resize → compress → check size.
    • Decrease quality until size limit met.
    • If still too large, try WebP.
  2. Client fallback (Canvas)
    • Resize → toBlob JPEG → reduce quality if needed.
  3. Authoritative server pipeline (Sharp, GD, ImageMagick, or equivalent)
    • Bound ingress before decode; detect MIME from bytes and require decoder success.
    • Reject excessive width, height, total pixels, frames, memory, or processing time.
    • Decode, orient, strip metadata, resize without enlargement, and canonicalize from pixels.
    • Preserve alpha where required; enforce final dimensions and byte limit after re-encode.
    • Never fall back to storing the original when processing fails.

Implementation Steps (High Level)

  1. Client compression service
    • Expose compressImage(file, options).
    • Use Squoosh with dynamic import.
    • Fallback to Canvas on error.
  2. Upload hook / handler
    • Validate input is image.
    • Compress transparently.
    • Upload compressed blob.
  3. Server middleware
    • Use Sharp to enforce limits.
    • Return 413 if still too large.
    • Attach compression stats to logs.

Required Defaults

  • maxWidth: 1920
  • maxHeight: 1920
  • maxSize: $512 * 1024$
  • quality: 75
  • minDimensions: 200x200 (server-side)

Anti-Patterns

  • ❌ Skipping server validation
  • ❌ Uploading original file on failure without logging
  • ❌ Enlarging images
  • ❌ Using blocking UI (must be transparent to user)

References (Load as Needed)

  • Client implementation: references/client.md
  • Client usage example: references/client-usage.md
  • Server middleware + routes: references/server.md
  • Storage adapters (S3/local): references/storage.md
  • Security checks: references/security.md
  • Managed SaaS background/logo/favicon lifecycle: saas-managed-visual-assets
  • Monitoring & analytics: references/monitoring.md
  • Performance targets: references/performance.md
  • Quality examples: references/quality-metrics.md
  • Environment variables: references/env.md
  • Docker (Sharp): references/docker.md
  • Implementation checklist: references/implementation-checklist.md

Output Expectations

  • Client compression completes in $100$–$500$ ms typical
  • Server compression $50$–$200$ ms typical
  • Bandwidth reduction $85$–$97%$

Checklist

Anti-Patterns

  • Trusting client output. Fix: decode and validate media on the server.
  • Treating file.type, extension, or magic bytes alone as authoritative. Fix: require content detection plus a successful bounded decode and canonical re-encode.
  • Uploading the original after failure without consent. Fix: show a recoverable error and record the reason.
  • Enlarging a small source. Fix: preserve its original dimensions.
  • Blocking the interface during compression. Fix: provide asynchronous progress, cancellation, and retry.
  • Applying one quality value to every format. Fix: tune by codec and inspect representative images.
  • Converting transparent logos/favicons to JPEG. Fix: use PNG or alpha-capable WebP.
  • Naming durable objects from the original filename. Fix: generate opaque random keys and store original names only as protected metadata when required.

Capability contract

Read and search the upload path first. Edit only when authorised; execute codec, size-limit, malformed-file, and server-validation tests when supported. Network access is optional for dependency verification.

  • Client: Squoosh primary + Canvas fallback
  • Client: size/dimension limits enforced
  • Server: authoritative content detection, bounded decode, canonical re-encode, and final limits
  • Server: pixel/frame/time/memory budgets and malformed/polyglot test corpus
  • Transparency: alpha preserved for logo/favicon profiles
  • Storage: random immutable keys, private origin, controlled delivery, and cleanup
  • Logging: compression stats & processing time
  • Storage: image saved with metadata
  • Tests: JPEG/PNG/WebP, large images, mobile

Inputs

ArtefactRequired?Purpose
Source images, display sizes, quality targets, formats, and delivery constraintsyesChoose safe optimisation

Outputs

  • Produce optimised assets and measured size, quality, format, and rendering evidence.

Degraded mode

Fallback without visual inspection or target rendering: retain originals and mark quality comparison unverified.

Workflow

Inventory usages, choose formats and dimensions, compress non-destructively, render representative states, compare quality and size, then update references.

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Image Compression」では何ができますか?

Use when implementing or reviewing client image optimisation plus authoritative server decode, validation, resize, metadata stripping, and canonical re-encoding. Use saas-managed-visual-assets for administrative asset lifecycle and frontend-performance for page budgets.

TypingMindでImage Compressionを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Image Compressionはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにImage Compressionをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/peterbamuhigire/chwezi-dev-engine/tree/main/skills/frontend-ux/image-compressionを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Image Compressionを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Image Compressionは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもImage Compressionを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Image Compression」は無料ですか?

はい。peterbamuhigireがGitHubでMITライセンスの下で公開しています。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇