pixel-icon-generator 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +146 -2
- package/bin/cli.mjs +73 -0
- package/package.json +35 -4
- package/skills/pixel-icons/SKILL.md +227 -0
- package/skills/pixel-icons/references/apple.json +28 -0
- package/skills/pixel-icons/references/cactus.json +28 -0
- package/skills/pixel-icons/references/ogre.json +34 -0
- package/skills/pixel-icons/references/relic.json +28 -0
- package/skills/pixel-icons/references/smack.json +27 -0
- package/skills/pixel-icons/scripts/pixelicon.mjs +346 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jahanvi Singh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,147 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pixel-icon-generator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An agent skill that turns a single word into a **16×16 pixel icon** in the style of [Pixtober 2024](https://jahanvi-pixtober-2024.framer.website/), Jahanvi Singh's daily pixel-icon series.
|
|
4
|
+
|
|
5
|
+
Ask your AI tool for "a pixel icon of a lantern" and you get `lantern.svg` in your project, ready for code or Figma.
|
|
6
|
+
|
|
7
|
+
**Website:** [pixelicons.iamjahanvi.com](https://pixelicons.iamjahanvi.com) has a library of 30 icons to download, an editor, a way to make icons with your own API key, and the copy-and-paste prompt.
|
|
8
|
+
|
|
9
|
+
## What you get
|
|
10
|
+
|
|
11
|
+
- **One idea per word.** The agent picks the strongest idea and tells you why in a line. For abstract words it picks a visual metaphor, for example "courage → a small shield with a heart".
|
|
12
|
+
- **Figma-ready SVGs**: one 1×1 `<rect>` per pixel, the same shape as a Figma export. Paste one into Figma and every pixel stays editable.
|
|
13
|
+
- **Only the SVG lands in your project.** The agent asks where to save it first, and keeps its working files elsewhere.
|
|
14
|
+
- **Built-in style checks**: a closed outline, no stray pixels, no anti-aliasing. The agent also renders each icon and looks at it before handing it over.
|
|
15
|
+
- **Plain-word edits**: "make the flame bigger" updates the file in place.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
### Claude app (web, desktop or mobile)
|
|
20
|
+
|
|
21
|
+
1. Make sure code execution is on: **Settings → Capabilities → "Code execution and file creation"**. On Team and Enterprise plans, an owner controls this.
|
|
22
|
+
2. Download [`pixel-icons.zip`](pixel-icons.zip) from this repo.
|
|
23
|
+
3. Go to **Customize → Skills**, click **+**, then **Create skill → Upload a skill**, and choose the ZIP.
|
|
24
|
+
4. Toggle the skill on.
|
|
25
|
+
|
|
26
|
+
These steps follow [Use skills in Claude](https://support.claude.com/en/articles/12512180-use-skills-in-claude). If the menus have moved, check there.
|
|
27
|
+
|
|
28
|
+
### Claude Code
|
|
29
|
+
|
|
30
|
+
Add the plugin from inside Claude Code:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
/plugin marketplace add iamjahanvi/pixel-icon-generator
|
|
34
|
+
/plugin install pixel-icons@pixel-icon-generator
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Cursor, Codex, OpenCode, Gemini CLI and other agents
|
|
38
|
+
|
|
39
|
+
Run this in your project and pick your tools when it asks:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx skills add iamjahanvi/pixel-icon-generator
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For GitHub Copilot, use the GitHub CLI:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
gh skill install iamjahanvi/pixel-icon-generator pixel-icons
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### With npm
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx pixel-icon-generator init # .agents/skills/ (Cursor, Codex, Copilot)
|
|
55
|
+
npx pixel-icon-generator init --claude # .claude/skills/ (Claude Code)
|
|
56
|
+
npx pixel-icon-generator init --cursor # .cursor/skills/ (Cursor only)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Add `--global` to install it in your home folder for every project, and `--force` to replace an existing copy. It needs Node 18 or newer.
|
|
60
|
+
|
|
61
|
+
### Any chatbot, without installing anything
|
|
62
|
+
|
|
63
|
+
On [the website](https://pixelicons.iamjahanvi.com/#install), open **Any chat** and type your word. **Open in Claude** or **Open in ChatGPT** starts a new chat with the prompt filled in; press send. For Gemini or any other chat, use **Copy prompt** and paste it in. Then paste the reply into the site's editor to check the icon and download the SVG. This works on free accounts.
|
|
64
|
+
|
|
65
|
+
### On the website, with your own API key
|
|
66
|
+
|
|
67
|
+
On [the website](https://pixelicons.iamjahanvi.com/#make), click **Make**, type a word and paste your [Anthropic API key](https://platform.claude.com/settings/keys). Your browser sends the request straight to Anthropic, so the key never reaches the site. The site checks the icon against the style rules, asks Claude to fix any problems, and gives you the SVG.
|
|
68
|
+
|
|
69
|
+
## Use it
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
make a pixel icon of a lantern
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The first time in a session, the agent asks which folder to save into, and suggests your existing icons folder if it finds one. Then it saves `lantern.svg` there.
|
|
76
|
+
|
|
77
|
+
To change it, just say what you want:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
make the flame bigger and the base wider
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The edit overwrites the same file. Your version control keeps the history.
|
|
84
|
+
|
|
85
|
+
Tips:
|
|
86
|
+
- **Concrete nouns work best**, like objects, food, plants, animals and places.
|
|
87
|
+
- **For abstract words, say the metaphor** if you have one in mind: "Monday, as a coffee-stained calendar".
|
|
88
|
+
- **Name colours only if you want something unusual.** By default, colours come from the real object: grey rock, a white mug, a terracotta pot.
|
|
89
|
+
|
|
90
|
+
## The style
|
|
91
|
+
|
|
92
|
+
The rules come from five of Jahanvi's Pixtober 2024 icons, which ship with the skill as references:
|
|
93
|
+
|
|
94
|
+
- A **1px pure black outline** that is always closed, with black for the lines inside too
|
|
95
|
+
- **Flat colour only**: no dithering, gradients or anti-aliasing
|
|
96
|
+
- **Tight palettes** of 2–4 colours plus black, taken from the **real object**
|
|
97
|
+
- **One shade per material** as a 1px band, and **thin 1px highlights**
|
|
98
|
+
- **Rounded corners** made from 1px diagonal steps, with the subject **filling the canvas** (14–16px)
|
|
99
|
+
|
|
100
|
+
## Repo layout
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
skills/pixel-icons/ ← the skill (this folder is what gets installed)
|
|
104
|
+
SKILL.md ← instructions the agent follows
|
|
105
|
+
scripts/pixelicon.mjs ← renderer and style checker (Node 18+, no dependencies)
|
|
106
|
+
references/ ← five Pixtober 2024 icons as JSON grids
|
|
107
|
+
.claude-plugin/ ← Claude Code plugin and marketplace manifests
|
|
108
|
+
bin/cli.mjs ← the npx installer
|
|
109
|
+
pixel-icons.zip ← the skill folder, zipped for uploading to Claude
|
|
110
|
+
site/ ← the website (static, no build step)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Using the tool on its own
|
|
114
|
+
|
|
115
|
+
Icons are stored as JSON: a palette and 16 rows of 16 characters, where `.` means transparent.
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{"name": "lantern",
|
|
119
|
+
"palette": {"K": "#000000", "b": "#d4a52a", "y": "#ffe08a"},
|
|
120
|
+
"grid": ["................", "...16 rows..."]}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
npx pixel-icon-generator check lantern.json # validate the style rules
|
|
125
|
+
npx pixel-icon-generator svg lantern.json --out src/icons # export an SVG
|
|
126
|
+
npx pixel-icon-generator png lantern.json --out view # enlarged PNG to look at
|
|
127
|
+
npx pixel-icon-generator preview page.html lantern.json # build a preview page
|
|
128
|
+
npx pixel-icon-generator import lantern.svg lantern # turn an SVG or PNG back into a grid
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## The website
|
|
132
|
+
|
|
133
|
+
`site/` is a static site with no build step. To work on it:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
cd site && python3 -m http.server 8765 # then open http://localhost:8765
|
|
137
|
+
node site/tools/sync-core.mjs # after changing the checker in pixelicon.mjs
|
|
138
|
+
node site/tools/test-site.mjs # checks the site matches the skill and every icon passes
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Credits
|
|
142
|
+
|
|
143
|
+
Style and reference icons by **Jahanvi Singh**: [Pixtober 2024](https://jahanvi-pixtober-2024.framer.website/) · [@me_Jahanvi](https://x.com/me_Jahanvi). Skill built with Claude. The site uses the [Allo](https://allo.joshpuckett.me) font by Josh Puckett, under the SIL Open Font License.
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
[MIT](LICENSE), covering the code, the skill and the icons.
|
package/bin/cli.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// pixel-icon-generator CLI
|
|
3
|
+
// init copy the pixel-icons skill into a project (or your home folder) so a coding agent can use it
|
|
4
|
+
// check | svg | png | preview | import pass straight through to the skill's pixelicon.mjs
|
|
5
|
+
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { spawnSync } from "node:child_process";
|
|
11
|
+
|
|
12
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const SKILL_SRC = path.resolve(here, "..", "skills", "pixel-icons");
|
|
14
|
+
const SCRIPT = path.join(SKILL_SRC, "scripts", "pixelicon.mjs");
|
|
15
|
+
|
|
16
|
+
const TARGETS = {
|
|
17
|
+
agents: ".agents/skills", // Cursor, Codex and other tools that follow the Agent Skills standard
|
|
18
|
+
claude: ".claude/skills", // Claude Code
|
|
19
|
+
cursor: ".cursor/skills", // Cursor-only
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const HELP = `pixel-icon-generator: 16x16 Pixtober-style pixel icons for coding agents
|
|
23
|
+
|
|
24
|
+
Usage
|
|
25
|
+
npx pixel-icon-generator init [--claude | --cursor] [--global] [--force]
|
|
26
|
+
|
|
27
|
+
Copies the pixel-icons skill into this project so your coding agent can use it.
|
|
28
|
+
(default) .agents/skills/pixel-icons Cursor, Codex and other Agent Skills tools
|
|
29
|
+
--claude .claude/skills/pixel-icons Claude Code
|
|
30
|
+
--cursor .cursor/skills/pixel-icons Cursor only
|
|
31
|
+
--global install in your home folder instead, for every project
|
|
32
|
+
--force replace an existing copy
|
|
33
|
+
|
|
34
|
+
npx pixel-icon-generator <check|svg|png|preview|import> ...
|
|
35
|
+
Runs the icon tool directly (see the README).
|
|
36
|
+
|
|
37
|
+
Then ask your agent: "make a pixel icon of a lantern".
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
function init(args) {
|
|
41
|
+
const flag = (f) => args.includes(f);
|
|
42
|
+
const kind = flag("--claude") ? "claude" : flag("--cursor") ? "cursor" : "agents";
|
|
43
|
+
if (flag("--claude") && flag("--cursor")) fail("Pick one of --claude or --cursor.");
|
|
44
|
+
const root = flag("--global") ? os.homedir() : process.cwd();
|
|
45
|
+
const dest = path.join(root, TARGETS[kind], "pixel-icons");
|
|
46
|
+
if (fs.existsSync(dest)) {
|
|
47
|
+
if (!flag("--force")) fail(`Already installed at ${dest}\nRun again with --force to replace it.`);
|
|
48
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
49
|
+
}
|
|
50
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
51
|
+
fs.cpSync(SKILL_SRC, dest, { recursive: true });
|
|
52
|
+
const shown = flag("--global") ? path.join("~", TARGETS[kind], "pixel-icons") : path.relative(process.cwd(), dest);
|
|
53
|
+
console.log(`Installed the pixel-icons skill at ${shown}`);
|
|
54
|
+
console.log(`\nTry it: ask your agent "make a pixel icon of a lantern".`);
|
|
55
|
+
if (kind === "agents") console.log(`Using Claude Code? Run with --claude instead, so it lands in .claude/skills.`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function fail(msg) {
|
|
59
|
+
console.error(msg);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const [cmd, ...rest] = process.argv.slice(2);
|
|
64
|
+
if (!cmd || cmd === "-h" || cmd === "--help" || cmd === "help") {
|
|
65
|
+
console.log(HELP);
|
|
66
|
+
} else if (cmd === "init") {
|
|
67
|
+
init(rest);
|
|
68
|
+
} else if (["check", "svg", "png", "preview", "import"].includes(cmd)) {
|
|
69
|
+
const r = spawnSync(process.execPath, [SCRIPT, cmd, ...rest], { stdio: "inherit" });
|
|
70
|
+
process.exit(r.status ?? 1);
|
|
71
|
+
} else {
|
|
72
|
+
fail(`Unknown command: ${cmd}\n\n${HELP}`);
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pixel-icon-generator",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "An agent skill that turns a word into a 16x16 pixel icon in the Pixtober style, saved as an SVG.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"pixel-icon-generator": "bin/cli.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"skills"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"pixel-art",
|
|
18
|
+
"icons",
|
|
19
|
+
"svg",
|
|
20
|
+
"agent-skills",
|
|
21
|
+
"claude",
|
|
22
|
+
"cursor",
|
|
23
|
+
"codex",
|
|
24
|
+
"pixtober",
|
|
25
|
+
"figma"
|
|
26
|
+
],
|
|
27
|
+
"author": "Jahanvi Singh (https://x.com/me_Jahanvi)",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/iamjahanvi/pixel-icon-generator.git"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://pixelicons.iamjahanvi.com",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/iamjahanvi/pixel-icon-generator/issues"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pixel-icons
|
|
3
|
+
description: Turn a word into a 16x16 pixel icon in the Pixtober style by Jahanvi Singh and save it as a Figma-ready SVG file. Use when someone asks for a pixel icon, pixel art icon or 16x16 icon of something.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Pixel icons (16×16, Pixtober style)
|
|
7
|
+
|
|
8
|
+
The style comes from **Pixtober by Jahanvi Singh** ([@me_Jahanvi](https://x.com/me_Jahanvi)), her daily pixel-icon series, specifically the colour icons of Pixtober 2024.
|
|
9
|
+
|
|
10
|
+
The user gives a word ("lantern", "Monday", "courage"). You pick **one idea** for it, draw it as a 16×16 colour pixel icon, save it as an SVG in the user's project, and refine it on request.
|
|
11
|
+
|
|
12
|
+
Every icon is authored as a text grid. A bundled script renders the grid to SVG and checks it. You never hand-write SVG.
|
|
13
|
+
|
|
14
|
+
## 1. The tool
|
|
15
|
+
|
|
16
|
+
The script is `scripts/pixelicon.mjs`, inside the folder this SKILL.md lives in. Resolve that folder's path first: it is wherever your agent loaded this skill from, for example `.agents/skills/pixel-icons/`, `.cursor/skills/pixel-icons/` or `.claude/skills/pixel-icons/`. Then run:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
node <skill-folder>/scripts/pixelicon.mjs <command>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
It needs only Node 18 or newer and has no dependencies. Don't install anything for it.
|
|
23
|
+
|
|
24
|
+
| Command | What it does |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `check a.json …` | Validates the grid and the hard style rules. Exits 1 on any error. |
|
|
27
|
+
| `png a.json … --out DIR` | Writes enlarged PNGs on a checkerboard, so you can look at your own work. |
|
|
28
|
+
| `svg a.json … --out DIR` | Writes the final SVG: one 1×1 `<rect>` per pixel and a `fill="none"` root, the same shape as a Figma export. |
|
|
29
|
+
| `preview page.html a.json --title "…"` | Writes a page showing the icon enlarged on a pixel grid, at 1×/2×/4×, with its palette and check results. |
|
|
30
|
+
| `import icon.svg name --out DIR` | Converts an existing pixel icon (SVG or PNG) back into a grid. Use it to edit an icon you saved earlier, or to read the user's own references. |
|
|
31
|
+
|
|
32
|
+
## 2. Files: what goes where
|
|
33
|
+
|
|
34
|
+
**Only the final SVG goes into the user's project.** Everything else is scratch: the JSON grid, the review PNG and the preview page.
|
|
35
|
+
|
|
36
|
+
- **Scratch work** goes in a temporary folder outside the project, such as a `pixel-icons/<word>/` folder inside the system temp directory, or your own scratch area if your environment has one. Never leave grids or PNGs in the repo.
|
|
37
|
+
- **Where to save the SVG: always ask first.** The first time in a session, ask the user which folder to save into before writing anything. If you can see an existing icons folder (`src/assets/icons/`, `public/icons/`, `icons/` and so on), offer it as the suggestion. Reuse the answer for the rest of the session.
|
|
38
|
+
- **File name**: `<word>.svg` in lowercase kebab-case (`hot-air-balloon.svg`). If a file with that name exists, ask before overwriting it.
|
|
39
|
+
- **Editing later**: to change an icon that's already in the project, `import` its SVG into scratch, edit the grid, then write the SVG back over the same file. Version control keeps the history, so don't create `-v2` copies in the project.
|
|
40
|
+
|
|
41
|
+
Icon grid format, for scratch files:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{"name": "coffee", "label": "Mug with steam",
|
|
45
|
+
"palette": {"K": "#000000", "a": "#f4f1ea", "b": "#cfc7b8", "c": "#6b3b1f"},
|
|
46
|
+
"grid": [
|
|
47
|
+
"................",
|
|
48
|
+
"... 16 rows, each exactly 16 characters ...",
|
|
49
|
+
"................"]}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
- `.` is transparent. Every other character must be a key in `palette`.
|
|
53
|
+
- `K` is always black, `#000000`.
|
|
54
|
+
- Use lowercase letters for the other colours.
|
|
55
|
+
|
|
56
|
+
## 3. The style (Pixtober 2024)
|
|
57
|
+
|
|
58
|
+
These come from the five Pixtober 2024 reference icons in section 5. The first group is hard rules that the artist stated directly or that hold in every reference. `check` enforces most of them.
|
|
59
|
+
|
|
60
|
+
**Hard rules**
|
|
61
|
+
- **The outline is 1px and pure black (`#000000`).** It wraps the entire silhouette with no gaps. Never skip it on lit edges, and never tint it.
|
|
62
|
+
- **No dithering, no anti-aliasing, no gradients.** Every pixel is a flat colour from the palette.
|
|
63
|
+
- **No stray pixels.** Every filled pixel touches another filled pixel, including diagonally.
|
|
64
|
+
- **The background is transparent.**
|
|
65
|
+
|
|
66
|
+
**Style habits**
|
|
67
|
+
- **Black also does the inner linework**: screens and bezels, finger gaps, pot rims, faces, and separations between parts. Shapes inside the icon are separated by black, not by a slightly different shade.
|
|
68
|
+
- **Colours come from the real object.** Every colour in the references is the thing's true colour: a red apple, a green leaf, a green cactus in a terracotta pot, a cream retro computer, a skin-toned fist, a steel-blue blade.
|
|
69
|
+
- Before choosing hex values, name each material's real-world colour: "rock is grey, snow is white, a ceramic mug is white, coffee is brown".
|
|
70
|
+
- Then pick a clean, slightly brightened version of that colour.
|
|
71
|
+
- Never choose a colour for mood or variety, such as purple mountains, a blue mug or a teal lid, unless the word itself names that colour or the object really comes in it.
|
|
72
|
+
- When an object comes in many colours, like mugs or cars, use its most typical one.
|
|
73
|
+
- Fantasy subjects follow their convention, like a green ogre.
|
|
74
|
+
- **Palettes are tight.** Objects use black plus 2–4 colours. A character can go up to about 9. There is no fixed shared palette.
|
|
75
|
+
- **Shading is one darker tone per material**, used as a 1px band along one side or the underside. Examples are the right column of the fist, the left column of the screen and the ogre's shadowed jaw. There is at most one shade per material, and never a gradient.
|
|
76
|
+
- **Highlights are thin**: a 1px curved streak, like the white line down the apple, or a few accent pixels, like the cactus tips. They are never a large blob.
|
|
77
|
+
- **Corners are rounded with 1px diagonal steps** in the outline, as on the apple's curves and the cut corners of the computer case.
|
|
78
|
+
- **The subject fills the canvas.** It usually spans 14–16px and can touch the canvas edge. Use the most recognisable view: side-on for fruit, plants and animals, front-on for devices and faces. Centre it.
|
|
79
|
+
- **Vertical objects keep their proportions.** For things that are naturally taller than they are wide, such as an ice cream cone, a light bulb, a bottle, a candle or a lantern, use the full 16px height but **no more than 14px of width**. Don't stretch them sideways to fill the square. A slim object can be narrower than 14px if that reads truer. The SVG stays 16×16: centre the drawing, leaving the outer columns empty.
|
|
80
|
+
- **Personality is welcome but optional.** A simple face is a 1px black eye or two and a short black mouth, like the smiling screen on the computer. A creature can have attitude, like the ogre. Use it when it suits the idea; never force a face onto every icon.
|
|
81
|
+
|
|
82
|
+
## 4. Workflow
|
|
83
|
+
|
|
84
|
+
1. **Pick one idea.**
|
|
85
|
+
- If the word is concrete, draw the thing itself, in its most recognisable form.
|
|
86
|
+
- If it's abstract (an emotion, a day, a concept), choose a strong visual metaphor without asking, for example "courage → a small shield with a heart".
|
|
87
|
+
- Say in one line which idea you chose and why.
|
|
88
|
+
- At 16px a face only works on a calm, flat area. Don't put one on top of an object's own defining line, like a bean's crease: the two lines read as a scar.
|
|
89
|
+
|
|
90
|
+
2. **Plan before writing pixels.** Decide:
|
|
91
|
+
- the silhouette's bounding box, which should span 14–16px; for a vertical object, up to 16px tall and at most 14px wide
|
|
92
|
+
- where the black inner lines go
|
|
93
|
+
- which side gets the shadow band
|
|
94
|
+
- where the highlight streak goes
|
|
95
|
+
- each material and its real-world colour, written as a short list like "mug: white ceramic, coffee: dark brown"
|
|
96
|
+
|
|
97
|
+
Then draw in layers: silhouette in base colours → black outline around it → black inner lines → shadow band → highlight.
|
|
98
|
+
|
|
99
|
+
3. **Write the grid row by row.** Count every row to exactly 16 characters, and check the left/right symmetry where the object should be symmetric.
|
|
100
|
+
|
|
101
|
+
4. **Run `check`, then fix every error.**
|
|
102
|
+
- For an outline gap, add black around the pixel listed.
|
|
103
|
+
- For a stray pixel, remove it or connect it.
|
|
104
|
+
- Treat warnings as judgement calls.
|
|
105
|
+
|
|
106
|
+
5. **Look at the result.** Run `png` and view the image. If you can't view images, re-read the grid row by row as a picture instead. Fix anything that reads badly at 16px, such as a muddy silhouette, a lopsided shape or an unclear subject.
|
|
107
|
+
- Would someone name the word from the 1× icon alone?
|
|
108
|
+
- Are these the colours this thing has in real life?
|
|
109
|
+
|
|
110
|
+
Repeat steps 3–5 until it passes and reads clearly.
|
|
111
|
+
|
|
112
|
+
6. **Deliver.**
|
|
113
|
+
- Ask where to save, if you haven't yet this session (section 2).
|
|
114
|
+
- Run `svg` into that folder, and `preview` for a page kept in scratch.
|
|
115
|
+
- Tell the user the file path and the preview page's path, plus your one-line idea.
|
|
116
|
+
- Ask whether to change anything.
|
|
117
|
+
|
|
118
|
+
7. **Refine.** The user asks for changes in plain words ("rounder", "add a handle", "warmer brown"). Edit the grid, re-run check → png → svg (writing over the same file) → preview, and report what changed. Change only what they asked for.
|
|
119
|
+
|
|
120
|
+
## 5. Reference icons (study these before drawing)
|
|
121
|
+
|
|
122
|
+
These are five of Jahanvi's Pixtober 2024 icons, converted pixel for pixel from her SVGs. The same grids are in `references/` as JSON. Each block lists the palette, then the 16 rows.
|
|
123
|
+
|
|
124
|
+
**apple**: K `#000000` · a `#f7203c` red · b `#ffffff` highlight · c `#2bca30` leaf
|
|
125
|
+
```
|
|
126
|
+
......K.........
|
|
127
|
+
.......K........
|
|
128
|
+
...KKK.K.KKKK...
|
|
129
|
+
..KaKcKKKaaaaK..
|
|
130
|
+
.KaKccKaaaaaaaK.
|
|
131
|
+
KaKccKaaaaaaaaaK
|
|
132
|
+
KaaKKaaaaaabaaaK
|
|
133
|
+
KaaaaaaaaaaabaaK
|
|
134
|
+
KaaaaaaaaaaabaaK
|
|
135
|
+
KaaaaaaaaaaabaaK
|
|
136
|
+
KaaaaaaaaaaabaaK
|
|
137
|
+
.KaaaaaaaaabaaK.
|
|
138
|
+
.KaaaaaaaaaaaaK.
|
|
139
|
+
..KaaaaaaaaaaK..
|
|
140
|
+
...KaaaKKaaaK...
|
|
141
|
+
....KKK..KKK....
|
|
142
|
+
```
|
|
143
|
+
The body fills the full 16px width. The highlight is a single 1px curved streak. The leaf sits inside the outline, and the stem is a 1px black diagonal.
|
|
144
|
+
|
|
145
|
+
**relic** (old computer with a face): K `#000000` · a `#eddfc5` cream case · b `#8ccdc0` screen · c `#549f90` screen shade
|
|
146
|
+
```
|
|
147
|
+
..KKKKKKKKKKKK..
|
|
148
|
+
.KaaaaaaaaaaaaK.
|
|
149
|
+
.KaaKKKKKKKKaaK.
|
|
150
|
+
.KaKcbbbbbbbKaK.
|
|
151
|
+
.KaKcbKbbbKbKaK.
|
|
152
|
+
.KaKcbKbKbKbKaK.
|
|
153
|
+
.KaKcbbbKbbbKaK.
|
|
154
|
+
.KaKcbbKKbbbKaK.
|
|
155
|
+
.KaKcbbbbbbbKaK.
|
|
156
|
+
.KaaKKKKKKKKaaK.
|
|
157
|
+
.KaaaaaaaaaaaaK.
|
|
158
|
+
.KaKKaaaaKKKKaK.
|
|
159
|
+
.KaaaaaaaaaaaaK.
|
|
160
|
+
..KKKKKKKKKKKK..
|
|
161
|
+
..KaaaaaaaaaaK..
|
|
162
|
+
..KKKKKKKKKKKK..
|
|
163
|
+
```
|
|
164
|
+
The case corners are cut by 1px. The screen has a black bezel with a 1px shade column on its left. The face is drawn in black lines, and the slots are black dashes.
|
|
165
|
+
|
|
166
|
+
**cactus**: K `#000000` · a `#8aab1f` cactus green · b `#c7532e` terracotta pot · c `#bfdd4c` light-green accents
|
|
167
|
+
```
|
|
168
|
+
.......KK.......
|
|
169
|
+
...K..KaaK......
|
|
170
|
+
..KaK.KaaK..K...
|
|
171
|
+
..KcK.KacK.KaK..
|
|
172
|
+
..KaK.KaaK.KaK..
|
|
173
|
+
..KaK.KaaKKKcK..
|
|
174
|
+
..KaaKKcaKaaaK..
|
|
175
|
+
...KcaKaaKKKK...
|
|
176
|
+
....KKKaaK......
|
|
177
|
+
......KaaK......
|
|
178
|
+
....KKKacKKK....
|
|
179
|
+
...KbbKaaKbbK...
|
|
180
|
+
...KbKKKKKKbK...
|
|
181
|
+
....KbbbbbbK....
|
|
182
|
+
....KbbbbbbK....
|
|
183
|
+
.....KKKKKK.....
|
|
184
|
+
```
|
|
185
|
+
The arms are 1px wide inside the outline. The light accents are single pixels. The pot rim is a black line, and the pot narrows at the bottom with diagonal steps.
|
|
186
|
+
|
|
187
|
+
**smack** (fist): K `#000000` · a `#ea924e` skin · b `#af5d1f` shade
|
|
188
|
+
```
|
|
189
|
+
................
|
|
190
|
+
................
|
|
191
|
+
................
|
|
192
|
+
...KKKKKKKKK....
|
|
193
|
+
..KaaaaaaaaaK...
|
|
194
|
+
.KaaaaaaaaaabK..
|
|
195
|
+
.KabKabKabKabK..
|
|
196
|
+
.KaaaaaaaaaabK..
|
|
197
|
+
.KabKabKabKabK..
|
|
198
|
+
.KabKabKabKabK..
|
|
199
|
+
.KabKabKabKabK..
|
|
200
|
+
..KK.KK.KKaKKK..
|
|
201
|
+
.......KaaaabK..
|
|
202
|
+
........KKKKK...
|
|
203
|
+
................
|
|
204
|
+
................
|
|
205
|
+
```
|
|
206
|
+
This one uses only 3 colours. The finger gaps are black, and the shade is a 1px column on each finger and along the right edge.
|
|
207
|
+
|
|
208
|
+
**ogre** (character): K `#000000` · a `#7dc03b` skin · b `#437d3d` skin shade · c `#913b21` loincloth · d `#b9eaf8` blade · e `#ffffff` eyes/teeth · f `#7bc0d3` blade shade · g `#7a7302` hilt · h `#fe0002` mouth · i `#b10a0c` mouth shade
|
|
209
|
+
```
|
|
210
|
+
......KKKK...K..
|
|
211
|
+
....KKaaaaKKKdK.
|
|
212
|
+
...KaaaaaaaaKdK.
|
|
213
|
+
.KKKaaaaaaaaKdfK
|
|
214
|
+
KaabKaaaaaaKKdfK
|
|
215
|
+
KaabbKKaaKKbKdfK
|
|
216
|
+
.KKaaeeaaeeaKdfK
|
|
217
|
+
...KaeKaaKeaKdfK
|
|
218
|
+
....KaaaaaaKKdfK
|
|
219
|
+
..KKbbehhebbKdK.
|
|
220
|
+
.KaaaabiibaKgggg
|
|
221
|
+
KbbKaaaaaaaaKbbK
|
|
222
|
+
.KK.KccccccK.KK.
|
|
223
|
+
....KaccccaK....
|
|
224
|
+
....KabccbaK....
|
|
225
|
+
.....KK..KK.....
|
|
226
|
+
```
|
|
227
|
+
This is the most complex reference, with 9 colours. The eyes are white with black pupils, the brow is angry, and a sword runs the full height. Note: the hilt row and the bottom of the loincloth skip the outline in this original. `check` flags those spots. Don't copy that; new icons always close the outline.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "apple",
|
|
3
|
+
"palette": {
|
|
4
|
+
"a": "#f7203c",
|
|
5
|
+
"K": "#000000",
|
|
6
|
+
"b": "#ffffff",
|
|
7
|
+
"c": "#2bca30"
|
|
8
|
+
},
|
|
9
|
+
"grid": [
|
|
10
|
+
"......K.........",
|
|
11
|
+
".......K........",
|
|
12
|
+
"...KKK.K.KKKK...",
|
|
13
|
+
"..KaKcKKKaaaaK..",
|
|
14
|
+
".KaKccKaaaaaaaK.",
|
|
15
|
+
"KaKccKaaaaaaaaaK",
|
|
16
|
+
"KaaKKaaaaaabaaaK",
|
|
17
|
+
"KaaaaaaaaaaabaaK",
|
|
18
|
+
"KaaaaaaaaaaabaaK",
|
|
19
|
+
"KaaaaaaaaaaabaaK",
|
|
20
|
+
"KaaaaaaaaaaabaaK",
|
|
21
|
+
".KaaaaaaaaabaaK.",
|
|
22
|
+
".KaaaaaaaaaaaaK.",
|
|
23
|
+
"..KaaaaaaaaaaK..",
|
|
24
|
+
"...KaaaKKaaaK...",
|
|
25
|
+
"....KKK..KKK...."
|
|
26
|
+
],
|
|
27
|
+
"label": "Apple"
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cactus",
|
|
3
|
+
"palette": {
|
|
4
|
+
"K": "#000000",
|
|
5
|
+
"a": "#8aab1f",
|
|
6
|
+
"b": "#c7532e",
|
|
7
|
+
"c": "#bfdd4c"
|
|
8
|
+
},
|
|
9
|
+
"grid": [
|
|
10
|
+
".......KK.......",
|
|
11
|
+
"...K..KaaK......",
|
|
12
|
+
"..KaK.KaaK..K...",
|
|
13
|
+
"..KcK.KacK.KaK..",
|
|
14
|
+
"..KaK.KaaK.KaK..",
|
|
15
|
+
"..KaK.KaaKKKcK..",
|
|
16
|
+
"..KaaKKcaKaaaK..",
|
|
17
|
+
"...KcaKaaKKKK...",
|
|
18
|
+
"....KKKaaK......",
|
|
19
|
+
"......KaaK......",
|
|
20
|
+
"....KKKacKKK....",
|
|
21
|
+
"...KbbKaaKbbK...",
|
|
22
|
+
"...KbKKKKKKbK...",
|
|
23
|
+
"....KbbbbbbK....",
|
|
24
|
+
"....KbbbbbbK....",
|
|
25
|
+
".....KKKKKK....."
|
|
26
|
+
],
|
|
27
|
+
"label": "Cactus"
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ogre",
|
|
3
|
+
"palette": {
|
|
4
|
+
"K": "#000000",
|
|
5
|
+
"a": "#7dc03b",
|
|
6
|
+
"b": "#437d3d",
|
|
7
|
+
"c": "#913b21",
|
|
8
|
+
"d": "#b9eaf8",
|
|
9
|
+
"e": "#ffffff",
|
|
10
|
+
"f": "#7bc0d3",
|
|
11
|
+
"g": "#7a7302",
|
|
12
|
+
"h": "#fe0002",
|
|
13
|
+
"i": "#b10a0c"
|
|
14
|
+
},
|
|
15
|
+
"grid": [
|
|
16
|
+
"......KKKK...K..",
|
|
17
|
+
"....KKaaaaKKKdK.",
|
|
18
|
+
"...KaaaaaaaaKdK.",
|
|
19
|
+
".KKKaaaaaaaaKdfK",
|
|
20
|
+
"KaabKaaaaaaKKdfK",
|
|
21
|
+
"KaabbKKaaKKbKdfK",
|
|
22
|
+
".KKaaeeaaeeaKdfK",
|
|
23
|
+
"...KaeKaaKeaKdfK",
|
|
24
|
+
"....KaaaaaaKKdfK",
|
|
25
|
+
"..KKbbehhebbKdK.",
|
|
26
|
+
".KaaaabiibaKgggg",
|
|
27
|
+
"KbbKaaaaaaaaKbbK",
|
|
28
|
+
".KK.KccccccK.KK.",
|
|
29
|
+
"....KaccccaK....",
|
|
30
|
+
"....KabccbaK....",
|
|
31
|
+
".....KK..KK....."
|
|
32
|
+
],
|
|
33
|
+
"label": "Ogre"
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "relic",
|
|
3
|
+
"palette": {
|
|
4
|
+
"K": "#000000",
|
|
5
|
+
"a": "#eddfc5",
|
|
6
|
+
"b": "#8ccdc0",
|
|
7
|
+
"c": "#549f90"
|
|
8
|
+
},
|
|
9
|
+
"grid": [
|
|
10
|
+
"..KKKKKKKKKKKK..",
|
|
11
|
+
".KaaaaaaaaaaaaK.",
|
|
12
|
+
".KaaKKKKKKKKaaK.",
|
|
13
|
+
".KaKcbbbbbbbKaK.",
|
|
14
|
+
".KaKcbKbbbKbKaK.",
|
|
15
|
+
".KaKcbKbKbKbKaK.",
|
|
16
|
+
".KaKcbbbKbbbKaK.",
|
|
17
|
+
".KaKcbbKKbbbKaK.",
|
|
18
|
+
".KaKcbbbbbbbKaK.",
|
|
19
|
+
".KaaKKKKKKKKaaK.",
|
|
20
|
+
".KaaaaaaaaaaaaK.",
|
|
21
|
+
".KaKKaaaaKKKKaK.",
|
|
22
|
+
".KaaaaaaaaaaaaK.",
|
|
23
|
+
"..KKKKKKKKKKKK..",
|
|
24
|
+
"..KaaaaaaaaaaK..",
|
|
25
|
+
"..KKKKKKKKKKKK.."
|
|
26
|
+
],
|
|
27
|
+
"label": "Relic (old computer)"
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "smack",
|
|
3
|
+
"palette": {
|
|
4
|
+
"K": "#000000",
|
|
5
|
+
"a": "#ea924e",
|
|
6
|
+
"b": "#af5d1f"
|
|
7
|
+
},
|
|
8
|
+
"grid": [
|
|
9
|
+
"................",
|
|
10
|
+
"................",
|
|
11
|
+
"................",
|
|
12
|
+
"...KKKKKKKKK....",
|
|
13
|
+
"..KaaaaaaaaaK...",
|
|
14
|
+
".KaaaaaaaaaabK..",
|
|
15
|
+
".KabKabKabKabK..",
|
|
16
|
+
".KaaaaaaaaaabK..",
|
|
17
|
+
".KabKabKabKabK..",
|
|
18
|
+
".KabKabKabKabK..",
|
|
19
|
+
".KabKabKabKabK..",
|
|
20
|
+
"..KK.KK.KKaKKK..",
|
|
21
|
+
".......KaaaabK..",
|
|
22
|
+
"........KKKKK...",
|
|
23
|
+
"................",
|
|
24
|
+
"................"
|
|
25
|
+
],
|
|
26
|
+
"label": "Smack (fist)"
|
|
27
|
+
}
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// pixelicon.mjs - tools for 16x16 pixel icons stored as JSON grids.
|
|
3
|
+
// Zero dependencies: needs only Node 18+.
|
|
4
|
+
//
|
|
5
|
+
// Icon JSON:
|
|
6
|
+
// {"name": "apple", "style": "color",
|
|
7
|
+
// "palette": {"K": "#000000", "a": "#f7203c"},
|
|
8
|
+
// "grid": ["................", ... 16 rows of 16 chars ...]}
|
|
9
|
+
// '.' is a transparent pixel; every other char must be a key in palette.
|
|
10
|
+
// "style" is "color" (Pixtober 2024, the default) or "bw" (Pixtober 2025 black & white).
|
|
11
|
+
//
|
|
12
|
+
// Commands:
|
|
13
|
+
// check ICON.json [...] validate grid + style rules
|
|
14
|
+
// svg ICON.json [...] [--out DIR] write NAME.svg (one <rect> per pixel)
|
|
15
|
+
// png ICON.json [...] [--scale 16] [--out DIR] enlarged PNG on a checkerboard, for looking at your own work
|
|
16
|
+
// preview OUT.html ICON.json [...] [--title T] side-by-side preview page
|
|
17
|
+
// import IMAGE.svg|IMAGE.png NAME [--out DIR] convert an existing pixel icon to a grid
|
|
18
|
+
|
|
19
|
+
import fs from "node:fs";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import zlib from "node:zlib";
|
|
22
|
+
|
|
23
|
+
const N = 16;
|
|
24
|
+
const OUTLINE = "#000000";
|
|
25
|
+
const USAGE = `pixelicon.mjs - tools for 16x16 pixel icons stored as JSON grids.
|
|
26
|
+
|
|
27
|
+
Commands:
|
|
28
|
+
check ICON.json [...] validate grid + style rules
|
|
29
|
+
svg ICON.json [...] [--out DIR] write NAME.svg (one <rect> per pixel)
|
|
30
|
+
png ICON.json [...] [--scale 16] [--out DIR] enlarged PNG on a checkerboard
|
|
31
|
+
preview OUT.html ICON.json [...] [--title T] side-by-side preview page
|
|
32
|
+
import IMAGE.svg|IMAGE.png NAME [--out DIR] convert an existing pixel icon to a grid`;
|
|
33
|
+
|
|
34
|
+
const esc = (s) => String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
35
|
+
|
|
36
|
+
function load(p) {
|
|
37
|
+
const d = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
38
|
+
if (!("name" in d)) d.name = path.basename(p, path.extname(p));
|
|
39
|
+
return d;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function check(d) {
|
|
43
|
+
const errs = [], warns = [];
|
|
44
|
+
const g = d.grid || [], pal = d.palette || {};
|
|
45
|
+
if (g.length !== N) errs.push(`grid has ${g.length} rows, needs ${N}`);
|
|
46
|
+
g.forEach((row, y) => {
|
|
47
|
+
if (row.length !== N) errs.push(`row ${y} has ${row.length} chars, needs ${N}`);
|
|
48
|
+
[...row].forEach((c, x) => {
|
|
49
|
+
if (c !== "." && !(c in pal)) errs.push(`(${x},${y}) uses '${c}', which is not in palette`);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
if (errs.length) return [errs, warns];
|
|
53
|
+
const outlineKeys = new Set(Object.keys(pal).filter((k) => pal[k].toLowerCase() === OUTLINE));
|
|
54
|
+
if (!outlineKeys.size) errs.push("no pure black (#000000) outline colour in palette");
|
|
55
|
+
const filled = (x, y) => x >= 0 && x < N && y >= 0 && y < N && g[y][x] !== ".";
|
|
56
|
+
const gaps = [], strays = [], used = new Set();
|
|
57
|
+
for (let y = 0; y < N; y++) {
|
|
58
|
+
for (let x = 0; x < N; x++) {
|
|
59
|
+
const c = g[y][x];
|
|
60
|
+
if (c === ".") continue;
|
|
61
|
+
used.add(c);
|
|
62
|
+
// outline rule: a coloured pixel may never touch transparency or the canvas edge
|
|
63
|
+
if (!outlineKeys.has(c) && [[1, 0], [-1, 0], [0, 1], [0, -1]].some(([dx, dy]) => !filled(x + dx, y + dy))) gaps.push([x, y]);
|
|
64
|
+
// stray rule: no pixel floating on its own (8-neighbourhood)
|
|
65
|
+
let touch = false;
|
|
66
|
+
for (let dx = -1; dx <= 1; dx++) for (let dy = -1; dy <= 1; dy++) if ((dx || dy) && filled(x + dx, y + dy)) touch = true;
|
|
67
|
+
if (!touch) strays.push([x, y]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const fmt = (pts) => pts.map(([x, y]) => `(${x},${y})`).join(", ");
|
|
71
|
+
if (gaps.length) errs.push("outline gap: coloured pixel touches transparency/edge at " + fmt(gaps));
|
|
72
|
+
if (strays.length) errs.push("stray pixel at " + fmt(strays));
|
|
73
|
+
const unused = Object.keys(pal).filter((k) => !used.has(k)).sort();
|
|
74
|
+
if (unused.length) warns.push("unused palette keys: " + unused.join(", "));
|
|
75
|
+
if (d.style === "bw") {
|
|
76
|
+
// black & white (Pixtober 2025): only pure black and white, and a 2px outer outline
|
|
77
|
+
const off = Object.entries(pal).filter(([, v]) => !["#000000", "#ffffff"].includes(v.toLowerCase())).map(([k, v]) => `${k} ${v}`);
|
|
78
|
+
if (off.length) errs.push("black & white icons use only #000000 and #ffffff, found " + off.join(", "));
|
|
79
|
+
const thin = [];
|
|
80
|
+
for (let y = 0; y < N; y++) for (let x = 0; x < N; x++) {
|
|
81
|
+
if (g[y][x] === "." || outlineKeys.has(g[y][x])) continue;
|
|
82
|
+
// every white pixel needs 2px of black between it and the outside (5x5 minus the far corners)
|
|
83
|
+
let near = false;
|
|
84
|
+
for (let dx = -2; dx <= 2 && !near; dx++) for (let dy = -2; dy <= 2; dy++) {
|
|
85
|
+
if ((dx || dy) && !(Math.abs(dx) === 2 && Math.abs(dy) === 2) && !filled(x + dx, y + dy)) { near = true; break; }
|
|
86
|
+
}
|
|
87
|
+
if (near) thin.push([x, y]);
|
|
88
|
+
}
|
|
89
|
+
if (thin.length) errs.push("outer outline thinner than 2px: white pixel too close to the outside at " + fmt(thin));
|
|
90
|
+
} else {
|
|
91
|
+
const ncol = [...used].filter((k) => !outlineKeys.has(k)).length;
|
|
92
|
+
if (ncol > 6) warns.push(`${ncol} colours besides black; objects usually need 2-4`);
|
|
93
|
+
}
|
|
94
|
+
const rows = [], cols = [];
|
|
95
|
+
for (let i = 0; i < N; i++) {
|
|
96
|
+
if ([...Array(N).keys()].some((x) => filled(x, i))) rows.push(i);
|
|
97
|
+
if ([...Array(N).keys()].some((y) => filled(i, y))) cols.push(i);
|
|
98
|
+
}
|
|
99
|
+
if (rows.length && Math.max(rows.at(-1) - rows[0], cols.at(-1) - cols[0]) + 1 < 12) warns.push("subject is small; icons usually span 14-16px");
|
|
100
|
+
return [errs, warns];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Same shape as a Figma export: one 1x1 <rect> per pixel, fill="none" root.
|
|
104
|
+
export function svg(d, size = N) {
|
|
105
|
+
const rects = [];
|
|
106
|
+
d.grid.forEach((row, y) => [...row].forEach((c, x) => {
|
|
107
|
+
if (c !== ".") rects.push(`<rect x="${x}" y="${y}" width="1" height="1" fill="${d.palette[c]}"/>`);
|
|
108
|
+
}));
|
|
109
|
+
return `<svg width="${size}" height="${size}" viewBox="0 0 ${N} ${N}" fill="none" shape-rendering="crispEdges" xmlns="http://www.w3.org/2000/svg">\n` + rects.join("\n") + "\n</svg>\n";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function gridSvg(d, cell = 16) {
|
|
113
|
+
const s = N * cell;
|
|
114
|
+
let lines = "";
|
|
115
|
+
for (let i = 0; i <= N; i++) lines += `<line x1="${i * cell}" y1="0" x2="${i * cell}" y2="${s}"/><line x1="0" y1="${i * cell}" x2="${s}" y2="${i * cell}"/>`;
|
|
116
|
+
const full = svg(d);
|
|
117
|
+
const inner = full.slice(full.indexOf(">\n") + 2, full.lastIndexOf("</svg>"));
|
|
118
|
+
return `<svg class="big" viewBox="0 0 ${s} ${s}" width="${s}" height="${s}" shape-rendering="crispEdges"><g transform="scale(${cell})">${inner}</g><g class="gl">${lines}</g></svg>`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function preview(out, icons, title) {
|
|
122
|
+
const cards = icons.map((d, i) => {
|
|
123
|
+
const [errs, warns] = check(d);
|
|
124
|
+
const status = errs.map((m) => `<li class="e">${esc(m)}</li>`).join("") + warns.map((m) => `<li class="w">${esc(m)}</li>`).join("");
|
|
125
|
+
const sw = Object.entries(d.palette).map(([k, v]) => `<span class="sw" style="background:${v}" title="${k} ${v}"></span>`).join("");
|
|
126
|
+
return `<figure>
|
|
127
|
+
<figcaption><b>${i + 1}</b> ${esc(d.label ?? d.name)}</figcaption>
|
|
128
|
+
<div class="checker">${gridSvg(d)}</div>
|
|
129
|
+
<div class="sizes"><div>${svg(d, 16)}<small>1x</small></div><div>${svg(d, 32)}<small>2x</small></div><div>${svg(d, 64)}<small>4x</small></div></div>
|
|
130
|
+
<div class="pal">${sw}</div>
|
|
131
|
+
${status ? "<ul>" + status + "</ul>" : '<p class="ok">passes checks</p>'}
|
|
132
|
+
</figure>`;
|
|
133
|
+
});
|
|
134
|
+
const page = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
135
|
+
<title>${esc(title)}</title><style>
|
|
136
|
+
:root{--bg:#f6f3ec;--card:#fffdf8;--ink:#1d1b18;--mute:#7a746a;--line:#e4ddd0}
|
|
137
|
+
@media (prefers-color-scheme:dark){:root{--bg:#191816;--card:#22201d;--ink:#f1ece2;--mute:#9b948a;--line:#34312c}}
|
|
138
|
+
body{margin:0;background:var(--bg);color:var(--ink);font:14px/1.4 ui-monospace,Menlo,monospace;padding:24px 16px}
|
|
139
|
+
h1{font-size:18px;margin:0 0 20px}
|
|
140
|
+
.row{display:flex;flex-wrap:wrap;gap:20px}
|
|
141
|
+
figure{margin:0;background:var(--card);border:1px solid var(--line);border-radius:10px;padding:14px;width:286px;max-width:100%;box-sizing:border-box}
|
|
142
|
+
figcaption{margin-bottom:10px} figcaption b{display:inline-block;min-width:20px}
|
|
143
|
+
.checker{background:repeating-conic-gradient(#ddd 0 25%,#fff 0 50%) 0 0/16px 16px;line-height:0;width:256px;max-width:100%}
|
|
144
|
+
.big{width:100%;height:auto;display:block} .gl line{stroke:rgba(0,0,0,.12);stroke-width:1}
|
|
145
|
+
.sizes{display:flex;gap:16px;align-items:flex-end;margin:12px 0} .sizes div{display:flex;flex-direction:column;align-items:center;gap:4px}
|
|
146
|
+
.sizes svg{image-rendering:pixelated} small{color:var(--mute)}
|
|
147
|
+
.pal{display:flex;gap:4px} .sw{width:18px;height:18px;border-radius:3px;border:1px solid var(--line)}
|
|
148
|
+
ul{margin:10px 0 0;padding-left:16px;font-size:12px} .e{color:#c2372b} .w{color:var(--mute)} .ok{color:var(--mute);font-size:12px;margin:10px 0 0}
|
|
149
|
+
</style></head><body><h1>${esc(title)}</h1><div class="row">${cards.join("")}</div></body></html>`;
|
|
150
|
+
fs.writeFileSync(out, page);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ---------- PNG encode / decode (8-bit, non-interlaced) ----------
|
|
154
|
+
|
|
155
|
+
const CRC_TABLE = (() => {
|
|
156
|
+
const t = new Uint32Array(256);
|
|
157
|
+
for (let n = 0; n < 256; n++) {
|
|
158
|
+
let c = n;
|
|
159
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
160
|
+
t[n] = c >>> 0;
|
|
161
|
+
}
|
|
162
|
+
return t;
|
|
163
|
+
})();
|
|
164
|
+
const crc32 = (buf) => {
|
|
165
|
+
let c = 0xffffffff;
|
|
166
|
+
for (const b of buf) c = CRC_TABLE[(c ^ b) & 0xff] ^ (c >>> 8);
|
|
167
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
168
|
+
};
|
|
169
|
+
function chunk(type, data) {
|
|
170
|
+
const len = Buffer.alloc(4); len.writeUInt32BE(data.length);
|
|
171
|
+
const td = Buffer.concat([Buffer.from(type, "ascii"), data]);
|
|
172
|
+
const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(td));
|
|
173
|
+
return Buffer.concat([len, td, crc]);
|
|
174
|
+
}
|
|
175
|
+
function encodePng(w, h, rgba) {
|
|
176
|
+
const raw = Buffer.alloc((w * 4 + 1) * h);
|
|
177
|
+
for (let y = 0; y < h; y++) {
|
|
178
|
+
raw[y * (w * 4 + 1)] = 0;
|
|
179
|
+
rgba.copy(raw, y * (w * 4 + 1) + 1, y * w * 4, (y + 1) * w * 4);
|
|
180
|
+
}
|
|
181
|
+
const ihdr = Buffer.alloc(13);
|
|
182
|
+
ihdr.writeUInt32BE(w, 0); ihdr.writeUInt32BE(h, 4);
|
|
183
|
+
ihdr[8] = 8; ihdr[9] = 6; ihdr[10] = 0; ihdr[11] = 0; ihdr[12] = 0;
|
|
184
|
+
return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", ihdr), chunk("IDAT", zlib.deflateSync(raw)), chunk("IEND", Buffer.alloc(0))]);
|
|
185
|
+
}
|
|
186
|
+
function decodePng(buf) {
|
|
187
|
+
let pos = 8, w, h, depth, ctype, interlace, plte = null, trns = null;
|
|
188
|
+
const idat = [];
|
|
189
|
+
while (pos < buf.length) {
|
|
190
|
+
const len = buf.readUInt32BE(pos), type = buf.toString("ascii", pos + 4, pos + 8), data = buf.subarray(pos + 8, pos + 8 + len);
|
|
191
|
+
if (type === "IHDR") { w = data.readUInt32BE(0); h = data.readUInt32BE(4); depth = data[8]; ctype = data[9]; interlace = data[12]; }
|
|
192
|
+
else if (type === "PLTE") plte = data;
|
|
193
|
+
else if (type === "tRNS") trns = data;
|
|
194
|
+
else if (type === "IDAT") idat.push(data);
|
|
195
|
+
else if (type === "IEND") break;
|
|
196
|
+
pos += 12 + len;
|
|
197
|
+
}
|
|
198
|
+
if (depth !== 8 || interlace) throw new Error("only 8-bit, non-interlaced PNGs are supported");
|
|
199
|
+
const ch = { 0: 1, 2: 3, 3: 1, 4: 2, 6: 4 }[ctype];
|
|
200
|
+
const stride = w * ch, raw = zlib.inflateSync(Buffer.concat(idat)), px = Buffer.alloc(stride * h);
|
|
201
|
+
for (let y = 0; y < h; y++) {
|
|
202
|
+
const f = raw[y * (stride + 1)], src = raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1));
|
|
203
|
+
for (let i = 0; i < stride; i++) {
|
|
204
|
+
const a = i >= ch ? px[y * stride + i - ch] : 0, b = y ? px[(y - 1) * stride + i] : 0, c = i >= ch && y ? px[(y - 1) * stride + i - ch] : 0;
|
|
205
|
+
let v = src[i];
|
|
206
|
+
if (f === 1) v += a; else if (f === 2) v += b; else if (f === 3) v += (a + b) >> 1;
|
|
207
|
+
else if (f === 4) { const p = a + b - c, pa = Math.abs(p - a), pb = Math.abs(p - b), pc = Math.abs(p - c); v += pa <= pb && pa <= pc ? a : pb <= pc ? b : c; }
|
|
208
|
+
px[y * stride + i] = v & 0xff;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const out = Buffer.alloc(w * h * 4);
|
|
212
|
+
for (let i = 0; i < w * h; i++) {
|
|
213
|
+
let r, g, b, al = 255;
|
|
214
|
+
if (ctype === 6) [r, g, b, al] = px.subarray(i * 4, i * 4 + 4);
|
|
215
|
+
else if (ctype === 2) [r, g, b] = px.subarray(i * 3, i * 3 + 3);
|
|
216
|
+
else if (ctype === 0) r = g = b = px[i];
|
|
217
|
+
else if (ctype === 4) { r = g = b = px[i * 2]; al = px[i * 2 + 1]; }
|
|
218
|
+
else { const k = px[i]; [r, g, b] = plte.subarray(k * 3, k * 3 + 3); al = trns && k < trns.length ? trns[k] : 255; }
|
|
219
|
+
out.set([r, g, b, al], i * 4);
|
|
220
|
+
}
|
|
221
|
+
return { w, h, px: out };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ---------- import ----------
|
|
225
|
+
|
|
226
|
+
const hex2 = (n) => n.toString(16).padStart(2, "0");
|
|
227
|
+
const NAMED = { black: "#000000", white: "#ffffff", red: "#ff0000" };
|
|
228
|
+
|
|
229
|
+
function cellsToIcon(cells, name) {
|
|
230
|
+
const count = new Map();
|
|
231
|
+
for (const row of cells) for (const c of row) if (c) count.set(c, (count.get(c) || 0) + 1);
|
|
232
|
+
// most-used colour first; ties keep first-seen order (matches the Python version)
|
|
233
|
+
const order = [...count.entries()].sort((p, q) => q[1] - p[1]);
|
|
234
|
+
const pool = [..."abcdefghijmnopqrstuvwxyz"], keys = new Map();
|
|
235
|
+
for (const [hx] of order) keys.set(hx, hx === OUTLINE ? "K" : pool.shift());
|
|
236
|
+
const palette = {};
|
|
237
|
+
for (const [hx, k] of keys) palette[k] = hx;
|
|
238
|
+
// only black and white means the Pixtober 2025 black & white style
|
|
239
|
+
const style = [...keys.keys()].every((hx) => hx === "#000000" || hx === "#ffffff") ? "bw" : "color";
|
|
240
|
+
return { name, style, palette, grid: cells.map((row) => row.map((c) => (c ? keys.get(c) : ".")).join("")) };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function importSvg(p, name) {
|
|
244
|
+
const src = fs.readFileSync(p, "utf8").replace(/<defs>[\s\S]*?<\/defs>/g, "");
|
|
245
|
+
const cells = Array.from({ length: N }, () => Array(N).fill(null));
|
|
246
|
+
for (const m of src.matchAll(/<rect\b([^>]*)\/?>/g)) {
|
|
247
|
+
const at = Object.fromEntries([...m[1].matchAll(/([\w-]+)="([^"]*)"/g)].map((a) => [a[1], a[2]]));
|
|
248
|
+
let fill = (at.fill || "").toLowerCase();
|
|
249
|
+
if (!fill || fill === "none" || fill.startsWith("url")) continue;
|
|
250
|
+
const x = parseFloat(at.x || 0), y = parseFloat(at.y || 0), w = parseFloat(at.width || 1), h = parseFloat(at.height || 1);
|
|
251
|
+
fill = NAMED[fill] || fill;
|
|
252
|
+
if (fill.length === 4) fill = "#" + [...fill.slice(1)].map((ch) => ch + ch).join("");
|
|
253
|
+
for (let j = 0; j < Math.round(h); j++) for (let i = 0; i < Math.round(w); i++) {
|
|
254
|
+
const X = Math.floor(x) + i, Y = Math.floor(y) + j;
|
|
255
|
+
if (X >= 0 && X < N && Y >= 0 && Y < N) cells[Y][X] = fill;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return cellsToIcon(cells, name);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function importPng(p, name) {
|
|
262
|
+
const { w, h, px } = decodePng(fs.readFileSync(p));
|
|
263
|
+
const at = (x, y) => { const i = (Math.min(y, h - 1) * w + Math.min(x, w - 1)) * 4; return px.subarray(i, i + 4).join(","); };
|
|
264
|
+
let best = null;
|
|
265
|
+
for (const scale of [1, 2, 3, 4, 8, 16, 32]) {
|
|
266
|
+
if (w < N * scale || h < N * scale) continue;
|
|
267
|
+
// art may sit off-grid by up to scale-1 px; reads are clamped
|
|
268
|
+
for (let ox = 0; ox < scale; ox++) for (let oy = 0; oy < scale; oy++) {
|
|
269
|
+
let bad = 0;
|
|
270
|
+
for (let y = 0; y < N; y++) for (let x = 0; x < N; x++) {
|
|
271
|
+
const b = new Set();
|
|
272
|
+
for (let i = 0; i < scale; i++) for (let j = 0; j < scale; j++) b.add(at(ox + x * scale + i, oy + y * scale + j));
|
|
273
|
+
if (b.size > 1) bad++;
|
|
274
|
+
}
|
|
275
|
+
// a 1x read is always "clean", so on a tie prefer the larger scale
|
|
276
|
+
if (!best || bad < best[0] || (bad === best[0] && scale > best[1])) best = [bad, scale, ox, oy];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const [, scale, ox, oy] = best;
|
|
280
|
+
const cells = [];
|
|
281
|
+
for (let y = 0; y < N; y++) {
|
|
282
|
+
const row = [];
|
|
283
|
+
for (let x = 0; x < N; x++) {
|
|
284
|
+
const [r, g, b, a] = at(ox + x * scale, oy + y * scale).split(",").map(Number);
|
|
285
|
+
row.push(a < 128 ? null : "#" + hex2(r) + hex2(g) + hex2(b));
|
|
286
|
+
}
|
|
287
|
+
cells.push(row);
|
|
288
|
+
}
|
|
289
|
+
return cellsToIcon(cells, name);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// ---------- png render for self-review ----------
|
|
293
|
+
|
|
294
|
+
function renderPng(d, scale) {
|
|
295
|
+
const S = N * scale, buf = Buffer.alloc(S * S * 4);
|
|
296
|
+
for (let y = 0; y < S; y++) for (let x = 0; x < S; x++) {
|
|
297
|
+
const v = ((Math.floor(x / scale) + Math.floor(y / scale)) % 2) ? 232 : 255;
|
|
298
|
+
buf.set([v, v, v, 255], (y * S + x) * 4);
|
|
299
|
+
}
|
|
300
|
+
d.grid.forEach((row, gy) => [...row].forEach((c, gx) => {
|
|
301
|
+
if (c === ".") return;
|
|
302
|
+
const h = d.palette[c].replace("#", "");
|
|
303
|
+
const rgb = [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
|
|
304
|
+
for (let y = gy * scale; y < (gy + 1) * scale; y++) for (let x = gx * scale; x < (gx + 1) * scale; x++) buf.set([...rgb, 255], (y * S + x) * 4);
|
|
305
|
+
}));
|
|
306
|
+
return encodePng(S, S, buf);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// ---------- cli ----------
|
|
310
|
+
|
|
311
|
+
function main(argv) {
|
|
312
|
+
if (!argv.length) { console.error(USAGE); process.exit(1); }
|
|
313
|
+
const [cmd, ...rest] = argv;
|
|
314
|
+
const opt = (flag, def) => (rest.includes(flag) ? rest[rest.indexOf(flag) + 1] : def);
|
|
315
|
+
const files = rest.filter((p, i) => !p.startsWith("--") && (i === 0 || !rest[i - 1].startsWith("--")));
|
|
316
|
+
const mk = (dir) => fs.mkdirSync(dir, { recursive: true });
|
|
317
|
+
if (cmd === "check") {
|
|
318
|
+
let bad = false;
|
|
319
|
+
for (const p of files) {
|
|
320
|
+
const [errs, warns] = check(load(p));
|
|
321
|
+
if (errs.length) bad = true;
|
|
322
|
+
console.log(`${p}: ${errs.length ? "FAIL" : "ok"}`);
|
|
323
|
+
errs.forEach((m) => console.log(" error:", m));
|
|
324
|
+
warns.forEach((m) => console.log(" warn: ", m));
|
|
325
|
+
}
|
|
326
|
+
process.exit(bad ? 1 : 0);
|
|
327
|
+
} else if (cmd === "svg") {
|
|
328
|
+
const out = opt("--out", "."); mk(out);
|
|
329
|
+
for (const p of files) { const d = load(p), dest = path.join(out, d.name + ".svg"); fs.writeFileSync(dest, svg(d)); console.log(dest); }
|
|
330
|
+
} else if (cmd === "png") {
|
|
331
|
+
const scale = parseInt(opt("--scale", "16"), 10), out = opt("--out", "."); mk(out);
|
|
332
|
+
for (const p of files) { const d = load(p), dest = path.join(out, d.name + ".png"); fs.writeFileSync(dest, renderPng(d, scale)); console.log(dest); }
|
|
333
|
+
} else if (cmd === "preview") {
|
|
334
|
+
preview(files[0], files.slice(1).map(load), opt("--title", "Pixel icons"));
|
|
335
|
+
console.log(files[0]);
|
|
336
|
+
} else if (cmd === "import") {
|
|
337
|
+
const d = (files[0].toLowerCase().endsWith(".svg") ? importSvg : importPng)(files[0], files[1]);
|
|
338
|
+
const out = opt("--out", "."); mk(out);
|
|
339
|
+
const dest = path.join(out, d.name + ".json");
|
|
340
|
+
fs.writeFileSync(dest, JSON.stringify(d, null, 1));
|
|
341
|
+
console.log(dest);
|
|
342
|
+
console.log(d.grid.join("\n"));
|
|
343
|
+
} else { console.error(USAGE); process.exit(1); }
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("pixelicon.mjs")) main(process.argv.slice(2));
|