---
name: image-toolkit-skill
version: "0.1.4"
description: |-
  Local raster image toolkit for frontend/public assets, content ops, SEO/Lighthouse/LCP workflows, static asset hygiene, and automated pipelines. Use when users mention image toolkit, image processing, compress/optimize images, convert to WebP/AVIF, resize/crop/rotate/flip, watermark, batch images, image metadata/EXIF, LCP image optimization, frontend image assets, or static image governance.
  中文触发：图片处理、图片压缩、压缩图片、图片格式转换、图片转 WebP/AVIF、图片裁剪、图片缩放、图片旋转、图片翻转、图片加水印、图片批量处理、图片元信息、图片太大、优化图片体积、LCP 图片优化、前端图片资源优化、静态资源图片治理。
  English triggers: image toolkit, image processing, compress/optimize/convert/resize/crop/rotate/flip/watermark image, image metadata, batch image processing, convert to webp/avif.
title: image-toolkit-skill
canonical_url: https://skilld.dev/gh/wghust/stark-skills/image-toolkit-skill
last_updated: 2026-10-07T01:19:14.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> 23 supporting files sit beside this SKILL.md. When the Skill refers to one, fetch https://skilld.dev/api/skills-raw/wghust/stark-skills/image-toolkit-skill/PATH with PATH replaced.
>
> If the user asked to install this Skill, run `npx skilld install wghust/stark-skills/image-toolkit-skill`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/image-toolkit-skill`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/wghust/stark-skills/image-toolkit-skill) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/image-toolkit-skill`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/image-toolkit-skill --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/image-toolkit-skill --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# image-toolkit-skill

> **Language**: Match the user's language when replying.

## Normative references（read order）

1. **This `SKILL.md`** — triggers, AI routing, defaults, safety boundaries.
2. **`USAGE.md`** — **skill package layout** (no fixed global path), **`npm install`**, **run from any cwd** with absolute paths, **troubleshooting**, **`--report` JSON** for CI.

## Commands

本技能是**自包含目录**；安装与调用方式见 **`USAGE.md`**（含：在技能包根目录 `npm install`；可用 **`node <skill-root>/bin/image-toolkit.mjs`** 在用户项目目录下配合绝对路径运行）。

示例（当前 shell 已在技能根目录时）：

```bash
node bin/image-toolkit.mjs <operation> [options]
# or: npm start -- <operation> ...
```

Supported operations: `compress`, `convert`, `resize`, `crop`, `rotate`, `flip`, `watermark`, `metadata`, `batch`.

## AI routing (how to use)

1. If the user wants **lossless/quality tradeoff tuning** or **directory-wide** optimization, prefer `compress` or `batch`.
2. If the user wants **WebP/AVIF modernization**, use `convert` with `--format`, or `batch` with a `convert` step.
3. If the user wants **fixed widths/heights** or **max edge** constraints, use `resize` (fit `inside`, preserves aspect by default).
4. If the user wants **fixed aspect covers**, use `crop --ratio` (center crop) or explicit `--left --top --cropWidth --cropHeight`.
5. If the user wants **EXIF orientation normalization**, use `rotate --angle auto`.
6. If the user wants **auditing only** (no image writes), use `metadata`.
7. If the user describes **multi-step pipelines** (“先缩放再转 webp 再压质量”), prefer `batch --config image-toolkit.config.json`.

**Do not** use this skill for remote URL downloads, SVG rewriting, GIF/video, CDN upload, or automatic codebase reference rewrites (out of scope for v1).

## Host-agnostic note（Codex / Claude Code / Cursor / …）

- **Do not hard-code** a specific repo layout or editor global path when generating commands for the user.
- Resolve **skill root** from where this skill package actually lives on disk (the directory containing `package.json` and `bin/image-toolkit.mjs`).
- Prefer absolute paths for `--input` / `--output` / `--config` when the shell cwd is the user’s app project. Details: **`USAGE.md` → 方式 B**.

## Defaults & safety

- Default `--output`: `./image-toolkit-output`
- Default `--quality`: `75`; default compress long-edge cap `--maxWidth`: `1920` (when not overridden)
- Default **does not overwrite inputs**; outputs go under `--output`
- If an output file exists, the tool **skips** unless `--overwrite`
- Unsupported extensions (SVG/GIF/ICO/BMP/TIFF/…) are **skipped** with `unsupported format` in the report
- `--strict` fails fast on the first per-file error
- Recursive directory scans are **on** unless `--no-recursive`
- When output is nested inside input, the scanner **excludes** the output subtree from inputs (except `metadata`, which scans normally)

## Report

Every run prints a text **Image Toolkit Report** (summary + per-file lines). Optional `--report out.json` writes JSON (**字段契约见 `USAGE.md`**)。

## Examples

```bash
node bin/image-toolkit.mjs compress --input ./image.png --output ./dist --quality 75
node bin/image-toolkit.mjs convert --input ./images --output ./dist --format webp --quality 80
node bin/image-toolkit.mjs resize --input ./banner.jpg --output ./dist --width 1200
node bin/image-toolkit.mjs crop --input ./banner.jpg --output ./dist --ratio 16:9
node bin/image-toolkit.mjs rotate --input ./a.jpg --output ./dist --angle auto
node bin/image-toolkit.mjs flip --input ./a.jpg --output ./dist --direction horizontal
node bin/image-toolkit.mjs watermark --input ./a.jpg --output ./dist --text "AInvest" --position bottom-right
node bin/image-toolkit.mjs metadata --input ./images
node bin/image-toolkit.mjs batch --config ./examples/image-toolkit.config.json
```

### Batch config shape

See `examples/image-toolkit.config.json`. Supported step types: `resize`, `convert`, `compress`, `rotate`, `flip`, `crop`.

## Implementation notes (for agents)

- Stack: **Node.js + sharp** (native dependency; `npm install` in skill package root — see **`USAGE.md`** if load fails).
- Trigger mapping hints:
  - “转 webp/avif” → `convert` or `batch`
  - “压体积 / Lighthouse / LCP 优化” → `compress` or chained `batch`
  - “封面 16:9 / 头像 1:1” → `crop --ratio …`
  - “读取宽高 EXIF” → `metadata`
