---
name: create-favicon
description: |-
  Generate a standards-aligned browser favicon.ico from a user-supplied source image, embedding PNG rasters at 32×32, 48×48, and 180×180 in one ICO container. Use when the user asks to create a favicon, 生成 favicon、网站图标、从图片做 ico、favicon.ico、create favicon from image.
  从用户提供的源图生成含 32/48/180 三档尺寸的 favicon.ico（ICO 内嵌 PNG）。若用户未上传或未指定可用源图，必须中止并提示上传/路径。
title: create-favicon
canonical_url: https://skilld.dev/gh/wghust/stark-skills/create-favicon
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.
>
> Supporting files, fetch one when the Skill refers to it: [references/ico-format-and-browser-notes.md](https://skilld.dev/api/skills-raw/wghust/stark-skills/create-favicon/references/ico-format-and-browser-notes.md), [USAGE.md](https://skilld.dev/api/skills-raw/wghust/stark-skills/create-favicon/USAGE.md).
>
> If the user asked to install this Skill, run `npx skilld install wghust/stark-skills/create-favicon`. 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/create-favicon`, 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/create-favicon) 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/create-favicon`. 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/create-favicon --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/create-favicon --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.

# create-favicon

> **Language**: Match the user’s language (中文提问则中文回复).

## Normative references (read before generating)

1. `references/ico-format-and-browser-notes.md` — ICO 结构、MIME、尺寸与 Apple Touch Icon 说明。
2. `USAGE.md` — 输入输出约定与无图门禁话术。

---

## Step 0 · Mandatory source image gate（必须最先执行）

**DO NOT** resize, pack ICO, or write `favicon.ico` until a **usable source image** is confirmed.

Treat the source as **present** only if **至少一项**成立：

- 用户在对话中 **附加了图片**；或
- 用户给出了 **可读的绝对/相对路径**，且你能 `read_file`/打开该图像文件；或
- 用户 **明确指定** 工作区内某文件为源图（例如 `@public/logo.png`），且该文件为常见栅格/矢量图格式（PNG、JPEG、WebP、GIF、SVG 等）。

**IF** none of the above applies — including when the user only says “做个 favicon”而未指定用哪张图、也未附加图片：

- **STOP** immediately.
- **DO NOT** invent a placeholder icon, **DO NOT** pick a random image from the repo, **DO NOT** run conversion tools.
- Reply clearly, e.g. **「请先上传用作 favicon 的源图片，或提供可访问的图片文件路径（如 `public/logo.png`），我才能生成 `favicon.ico`。」**

---

## Step 1 · Resolve output path

- Ask or infer where to write `favicon.ico` (e.g. `public/favicon.ico`, `app/favicon.ico`, or site root). Do not overwrite without user confirmation if a file already exists.

---

## Step 2 · Generate ICO（不污染用户业务项目）

**Goal**: only write the user-approved **`favicon.ico`** into their **application** tree (e.g. `public/favicon.ico`). **Do not** run `pnpm install` / `pnpm build` for this CLI in an **unrelated** app repo root, and **do not** add `node_modules`, CLI `dist/`, or a copied `tools/create-favicon` tree there **unless the user explicitly asks to vendor the tool** (then warn about gitignore / lockfiles).

Pick **one** path **in order**:

1. **This skills monorepo checkout** — If the workspace is (or you can resolve) the repo that already contains `tools/create-favicon/package.json` (e.g. **`stark-skills`**):  
   `cd <absolute-path-to>/tools/create-favicon && pnpm install && pnpm build`  
   then run **`node`** with **absolute** `--input` and `--output` (output may point into the user’s app directory).

2. **Disposable build in OS temp** — If the user’s open project is **only** their site/app and does **not** ship this CLI: clone or copy **only** `tools/create-favicon` (and needed files) under **`$TMPDIR`** / `%TEMP%` / `mktemp -d`, run `pnpm install && pnpm build` **there**, then:  
   `node dist/cli.js --input "<absolute source image>" --output "<absolute path in user app>/favicon.ico"`  
   Remove the temp tree when done (keep the ICO).

3. **Published runner (if documented)** — If this CLI is published as an **`npx <package>`** or global binary in project docs, prefer it so the user’s app directory does not gain a local `node_modules` for this workflow.

4. **Non-Node fallback** — **ImageMagick** / **`magick`** or another approach that satisfies **ICO + three PNG payloads** without leaving Node build artifacts in the user’s app; see `USAGE.md`.

```bash
# Example after building CLI in monorepo or temp dir — always use absolute paths.
# Default: --fit contain（整图可见，非方形时透明或白边，不默认裁切）
node dist/cli.js --input "<absolute-path-to-source.png>" --output "<absolute-path-to-user-app>/public/favicon.ico"

# Only if the user explicitly wants 铺满/裁剪去留白（需确认可能裁掉边缘）:
node dist/cli.js --input "..." --output "..." --fit cover
```

**Framing（构图）**

- **默认 `contain`**：等比缩放，**整张源图都保留在方形内**，居中；有 alpha 的源图留白为**透明**；无 alpha（如 JPEG）留白为**白色**（要透明边请用 PNG/SVG）。**禁止**在用户未要求时用 `cover` 把图裁成「另一张」。
- **`--fit cover`**：**仅当**用户明确说不要留白、要填满、裁剪铺满等，并**提示可能裁边**后，再传入 CLI 或等效流程。

**Multi-size / scaling（多尺寸与画质）**

- **32 / 48 / 180** 共用 **同一套** `fit`、居中、留白规则；只是像素变多/变少，**不要**让某一档单独换裁切方式。
- 参考 CLI 使用 **Lanczos（lanczos3）** 缩放；若 stderr 出现 **过小位图源** 警告，提醒用户换 **更高分辨率** 或 **SVG**。

The CLI writes a single `favicon.ico` containing **three** embedded **PNG** blobs at **32×32**, **48×48**, and **180×180** (ICO container per Windows icon layout; see references).

**Fallback** — if every CLI path fails:

- Use step **4** or stop and explain what is missing (network for clone, Node, `sharp`, or ImageMagick).

---

## Step 3 · Quick verification

- Confirm file size is non-zero and magic `00 00 01 00` at offset 0 (ICO), image count `03 00` at offset 4.
- Optionally decode each embedded PNG signature `89 50 4E 47` at offsets listed in directory entries.

---

## Step 4 · Tell the user

- Output path, the three embedded sizes, **framing used**（`contain` = 整图可见 / `cover` = 可能裁边）, **that all three sizes share the same composition**（仅分辨率不同）, and **high-quality (Lanczos) resize** unless another tool path was used. If `cover` was used, **do not** imply the icon is pixel-identical to the uncropped source. If a small-source warning appeared, relay it. Mention that **iOS 主屏幕** 常用独立 `apple-touch-icon.png`；详见 `references/ico-format-and-browser-notes.md`。
