chess2img 0.1.1 → 0.1.3
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/README.md +134 -121
- package/assets/readme/chesscom-opening-e4-cburnett.png +0 -0
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -1,145 +1,131 @@
|
|
|
1
1
|
# chess2img
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<div align="center">
|
|
4
|
+
<img src="./assets/themes/cburnett/wK.png" alt="chess2img king icon" width="88" />
|
|
5
|
+
<p>Generate PNG chessboard images from FEN, PGN, or board arrays in Node.js.</p>
|
|
6
|
+
<p>
|
|
7
|
+
<a href="https://www.npmjs.com/package/chess2img"><img src="https://img.shields.io/npm/v/chess2img" alt="npm version" /></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/chess2img"><img src="https://img.shields.io/npm/dm/chess2img" alt="npm downloads" /></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/chess2img"><img src="https://img.shields.io/npm/l/chess2img" alt="license" /></a>
|
|
10
|
+
<a href="https://github.com/ZiriloXXX/chess2img"><img src="https://img.shields.io/github/stars/ZiriloXXX/chess2img" alt="GitHub stars" /></a>
|
|
11
|
+
</p>
|
|
12
|
+
</div>
|
|
4
13
|
|
|
5
|
-
|
|
14
|
+
## Overview
|
|
6
15
|
|
|
7
|
-
|
|
16
|
+
`chess2img` renders chessboard PNGs from FEN, PGN, or board-array inputs with a small Promise-based API for JavaScript and TypeScript users on Node.js.
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
npm install chess2img
|
|
11
|
-
```
|
|
18
|
+
## Features
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
- Render PNG chessboard images from `fen`, `pgn`, or `board` input.
|
|
21
|
+
- Use five bundled built-in themes: `merida`, `alpha`, `cburnett`, `cheq`, and `leipzig`.
|
|
22
|
+
- Highlight squares such as the last move or key tactical ideas.
|
|
23
|
+
- Customize board colors, size, padding, and board orientation.
|
|
24
|
+
- Use either the functional `renderChess(...)` API or the `ChessImageGenerator` class API.
|
|
25
|
+
- Register custom themes globally or pass a theme inline for one-off rendering.
|
|
26
|
+
- Consume the package from both JavaScript and TypeScript projects.
|
|
14
27
|
|
|
15
|
-
|
|
16
|
-
- native build support for `canvas`
|
|
17
|
-
- common Linux packages usually include Cairo, Pango, libpng, libjpeg, giflib, a C/C++ toolchain, and Python for `node-gyp`
|
|
28
|
+
## Example Output
|
|
18
29
|
|
|
19
|
-
|
|
30
|
+
Opening `1.e4` with a Chess.com-like board palette, highlighted origin and destination squares, and the built-in `cburnett` piece set.
|
|
31
|
+
|
|
32
|
+
<img src="./assets/readme/chesscom-opening-e4-cburnett.png" alt="Opening 1.e4 example board" width="480" />
|
|
20
33
|
|
|
21
34
|
## Quick Start
|
|
22
35
|
|
|
36
|
+
```bash
|
|
37
|
+
npm install chess2img
|
|
38
|
+
```
|
|
39
|
+
|
|
23
40
|
```ts
|
|
41
|
+
import { writeFile } from "node:fs/promises";
|
|
24
42
|
import { renderChess } from "chess2img";
|
|
25
43
|
|
|
26
|
-
const
|
|
27
|
-
fen: "
|
|
44
|
+
const png = await renderChess({
|
|
45
|
+
fen: "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1",
|
|
28
46
|
size: 480,
|
|
29
|
-
style: "
|
|
47
|
+
style: "cburnett",
|
|
48
|
+
colors: {
|
|
49
|
+
lightSquare: "#EEEED2",
|
|
50
|
+
darkSquare: "#769656",
|
|
51
|
+
highlight: "rgba(246, 246, 105, 0.6)",
|
|
52
|
+
},
|
|
53
|
+
highlightSquares: ["e2", "e4"],
|
|
30
54
|
});
|
|
55
|
+
|
|
56
|
+
await writeFile("board.png", png);
|
|
31
57
|
```
|
|
32
58
|
|
|
33
|
-
|
|
59
|
+
`renderChess(...)` returns a `Promise<Buffer>` containing PNG data.
|
|
34
60
|
|
|
35
|
-
|
|
36
|
-
const { ChessImageGenerator } = require("chess2img");
|
|
61
|
+
## Installation
|
|
37
62
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
style: "alpha",
|
|
42
|
-
});
|
|
63
|
+
```bash
|
|
64
|
+
npm install chess2img
|
|
65
|
+
```
|
|
43
66
|
|
|
44
|
-
|
|
45
|
-
generator.setHighlights(["e4", "e5"]);
|
|
67
|
+
### Node And Canvas Requirements
|
|
46
68
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
- Node.js `18+`
|
|
70
|
+
- native build support for `canvas`
|
|
71
|
+
- common Linux packages usually include Cairo, Pango, libpng, libjpeg, giflib, a C/C++ toolchain, and Python for `node-gyp`
|
|
50
72
|
|
|
51
|
-
|
|
52
|
-
```
|
|
73
|
+
If `canvas` fails to install, verify your system packages first. The library ships `canvas` as a direct dependency, but native prerequisites still need to exist on the host.
|
|
53
74
|
|
|
54
|
-
##
|
|
75
|
+
## Basic Usage
|
|
76
|
+
|
|
77
|
+
### Functional API
|
|
55
78
|
|
|
56
79
|
```ts
|
|
57
|
-
import {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
[null, null, null, null, null, null, null, null],
|
|
65
|
-
[null, null, null, null, null, null, null, null],
|
|
66
|
-
[null, null, null, null, null, null, null, null],
|
|
67
|
-
["P", "P", "P", "P", "P", "P", "P", "P"],
|
|
68
|
-
["R", "N", "B", "Q", "K", "B", "N", "R"],
|
|
69
|
-
],
|
|
70
|
-
size: 640,
|
|
71
|
-
style: "cburnett",
|
|
80
|
+
import { writeFile } from "node:fs/promises";
|
|
81
|
+
import { renderChess } from "chess2img";
|
|
82
|
+
|
|
83
|
+
const png = await renderChess({
|
|
84
|
+
fen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
|
|
85
|
+
size: 480,
|
|
86
|
+
style: "merida",
|
|
72
87
|
});
|
|
73
88
|
|
|
74
|
-
|
|
75
|
-
await generator.loadFEN("4k3/8/8/3p4/4P3/8/8/4K3 w - - 0 1");
|
|
76
|
-
await generator.toFile("board.png");
|
|
89
|
+
await writeFile("board.png", png);
|
|
77
90
|
```
|
|
78
91
|
|
|
79
|
-
## API
|
|
80
|
-
|
|
81
92
|
### Class API
|
|
82
93
|
|
|
83
94
|
```ts
|
|
95
|
+
import { ChessImageGenerator } from "chess2img";
|
|
96
|
+
|
|
84
97
|
const generator = new ChessImageGenerator({
|
|
85
98
|
size: 800,
|
|
86
|
-
style: "
|
|
87
|
-
flipped: false,
|
|
99
|
+
style: "alpha",
|
|
88
100
|
});
|
|
89
101
|
|
|
90
|
-
await generator.
|
|
91
|
-
generator.setHighlights(["e4", "
|
|
102
|
+
await generator.loadPGN("1. e4 e5 2. Nf3 Nc6 3. Bb5 a6");
|
|
103
|
+
generator.setHighlights(["e4", "e5"]);
|
|
92
104
|
|
|
93
|
-
const buffer = await generator.toBuffer();
|
|
94
105
|
await generator.toFile("board.png");
|
|
95
106
|
```
|
|
96
107
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
- `loadFEN(fen: string): Promise<void>`
|
|
100
|
-
- `loadPGN(pgn: string): Promise<void>`
|
|
101
|
-
- `loadBoard(board: BoardArray): Promise<void>`
|
|
102
|
-
- `setHighlights(squares: Square[]): void`
|
|
103
|
-
- `clearHighlights(): void`
|
|
104
|
-
- `toBuffer(): Promise<Buffer>`
|
|
105
|
-
- `toFile(filePath: string): Promise<void>`
|
|
108
|
+
### JavaScript Usage
|
|
106
109
|
|
|
107
|
-
|
|
110
|
+
```js
|
|
111
|
+
const { renderChess } = require("chess2img");
|
|
112
|
+
const { writeFile } = require("node:fs/promises");
|
|
108
113
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
async function main() {
|
|
115
|
+
const png = await renderChess({
|
|
116
|
+
fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1",
|
|
117
|
+
style: "merida",
|
|
118
|
+
});
|
|
113
119
|
|
|
114
|
-
|
|
120
|
+
await writeFile("board.png", png);
|
|
121
|
+
}
|
|
115
122
|
|
|
116
|
-
|
|
117
|
-
const buffer = await renderChess({
|
|
118
|
-
fen,
|
|
119
|
-
size: 800,
|
|
120
|
-
style: "merida",
|
|
121
|
-
});
|
|
123
|
+
main().catch(console.error);
|
|
122
124
|
```
|
|
123
125
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
- `fen`
|
|
127
|
-
- `pgn`
|
|
128
|
-
- `board`
|
|
129
|
-
|
|
130
|
-
## Options Reference
|
|
131
|
-
|
|
132
|
-
- `size`: board size in pixels
|
|
133
|
-
- `padding`: `[top, right, bottom, left]`
|
|
134
|
-
- `flipped`: render from black's perspective when `true`
|
|
135
|
-
- `style`: built-in theme alias
|
|
136
|
-
- `theme`: built-in theme name, registered custom theme name, or inline `ThemeDefinition`
|
|
137
|
-
- `highlightSquares`: array of algebraic squares such as `["e4", "d5"]`
|
|
138
|
-
- `colors.lightSquare`
|
|
139
|
-
- `colors.darkSquare`
|
|
140
|
-
- `colors.highlight`
|
|
126
|
+
## Built-In Themes
|
|
141
127
|
|
|
142
|
-
|
|
128
|
+
Bundled built-in themes:
|
|
143
129
|
|
|
144
130
|
- `merida`
|
|
145
131
|
- `alpha`
|
|
@@ -147,6 +133,8 @@ const buffer = await renderChess({
|
|
|
147
133
|
- `cheq`
|
|
148
134
|
- `leipzig`
|
|
149
135
|
|
|
136
|
+
Built-in themes are vendored in-package and render through the same theme pipeline as custom themes.
|
|
137
|
+
|
|
150
138
|
## Custom Themes
|
|
151
139
|
|
|
152
140
|
Register a reusable theme globally:
|
|
@@ -158,7 +146,7 @@ registerTheme({
|
|
|
158
146
|
name: "custom-theme",
|
|
159
147
|
displayName: "Custom Theme",
|
|
160
148
|
license: "MIT",
|
|
161
|
-
attribution: "
|
|
149
|
+
attribution: "Theme author or package source",
|
|
162
150
|
pieces: {
|
|
163
151
|
// 12 canonical pieces required
|
|
164
152
|
},
|
|
@@ -175,7 +163,54 @@ Custom themes may use either:
|
|
|
175
163
|
- `svg` assets
|
|
176
164
|
- `png` assets
|
|
177
165
|
|
|
178
|
-
##
|
|
166
|
+
## API
|
|
167
|
+
|
|
168
|
+
### Public Exports
|
|
169
|
+
|
|
170
|
+
- `new ChessImageGenerator(options?)`
|
|
171
|
+
- `renderChess(options)`
|
|
172
|
+
- `registerTheme(theme)`
|
|
173
|
+
|
|
174
|
+
### Functional API
|
|
175
|
+
|
|
176
|
+
`renderChess(...)` accepts exactly one position source:
|
|
177
|
+
|
|
178
|
+
- `fen`
|
|
179
|
+
- `pgn`
|
|
180
|
+
- `board`
|
|
181
|
+
|
|
182
|
+
### Class API
|
|
183
|
+
|
|
184
|
+
Methods:
|
|
185
|
+
|
|
186
|
+
- `loadFEN(fen: string): Promise<void>`
|
|
187
|
+
- `loadPGN(pgn: string): Promise<void>`
|
|
188
|
+
- `loadBoard(board: BoardArray): Promise<void>`
|
|
189
|
+
- `setHighlights(squares: Square[]): void`
|
|
190
|
+
- `clearHighlights(): void`
|
|
191
|
+
- `toBuffer(): Promise<Buffer>`
|
|
192
|
+
- `toFile(filePath: string): Promise<void>`
|
|
193
|
+
|
|
194
|
+
Semantics:
|
|
195
|
+
|
|
196
|
+
- `setHighlights` replaces the current highlight set
|
|
197
|
+
- `clearHighlights` removes all highlights
|
|
198
|
+
- loading a new position clears highlights
|
|
199
|
+
- constructor defaults persist across position loads
|
|
200
|
+
|
|
201
|
+
### Options
|
|
202
|
+
|
|
203
|
+
- `size`: board size in pixels
|
|
204
|
+
- `padding`: `[top, right, bottom, left]`
|
|
205
|
+
- `flipped`: render from black's perspective when `true`
|
|
206
|
+
- `style`: built-in theme alias
|
|
207
|
+
- `theme`: built-in theme name, registered custom theme name, or inline `ThemeDefinition`
|
|
208
|
+
- `highlightSquares`: array of algebraic squares such as `["e4", "d5"]`
|
|
209
|
+
- `colors.lightSquare`
|
|
210
|
+
- `colors.darkSquare`
|
|
211
|
+
- `colors.highlight`
|
|
212
|
+
|
|
213
|
+
### Errors
|
|
179
214
|
|
|
180
215
|
The library exports:
|
|
181
216
|
|
|
@@ -185,30 +220,8 @@ The library exports:
|
|
|
185
220
|
- `RenderError`
|
|
186
221
|
- `IOError`
|
|
187
222
|
|
|
188
|
-
##
|
|
189
|
-
|
|
190
|
-
- `core` parses and validates chess position input into a canonical board model
|
|
191
|
-
- `themes` validates, registers, and resolves built-in or custom themes
|
|
192
|
-
- `render` rasterizes SVG or PNG theme assets and renders PNG output through `canvas`
|
|
193
|
-
- `api` orchestrates parsing, theme resolution, rendering, and file output
|
|
194
|
-
|
|
195
|
-
## Migration From `chess-image-generator`
|
|
196
|
-
|
|
197
|
-
| Old | New | Difference |
|
|
198
|
-
| --- | --- | --- |
|
|
199
|
-
| `loadArray` | `loadBoard` | renamed for clarity |
|
|
200
|
-
| `highlightSquares([...])` | `setHighlights([...])` | replacement semantics are explicit |
|
|
201
|
-
| `generateBuffer()` | `toBuffer()` | same role, new naming |
|
|
202
|
-
| `generatePNG(path)` | `toFile(path)` | IO is explicit in the API name |
|
|
203
|
-
| `style` only | `style` or `theme` | `theme` is the canonical path |
|
|
204
|
-
|
|
205
|
-
## Troubleshooting
|
|
206
|
-
|
|
207
|
-
- `canvas` install failures usually indicate missing native prerequisites on the host
|
|
208
|
-
- `ValidationError` from `renderChess` usually means multiple position inputs were provided or an option shape is invalid
|
|
209
|
-
- `ThemeError` usually indicates an unknown theme name or an incomplete custom theme definition
|
|
210
|
-
- `RenderError` usually indicates asset decoding/rasterization problems
|
|
223
|
+
## License
|
|
211
224
|
|
|
212
|
-
|
|
225
|
+
`chess2img` is distributed under the MIT license in package metadata.
|
|
213
226
|
|
|
214
|
-
Bundled built-in themes are derived from the upstream `andyruwruw/chess-image-generator` resource packs and are vendored in-package for deterministic installs. Provenance and licensing notes live in [ATTRIBUTION.md](
|
|
227
|
+
Bundled built-in themes are derived from the upstream `andyruwruw/chess-image-generator` resource packs and are vendored in-package for deterministic installs. Provenance and licensing notes live in [ATTRIBUTION.md](./ATTRIBUTION.md).
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chess2img",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Modern chess board image rendering for Node.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -11,6 +11,16 @@
|
|
|
11
11
|
"url": "https://github.com/ZiriloXXX/chess2img/issues"
|
|
12
12
|
},
|
|
13
13
|
"homepage": "https://github.com/ZiriloXXX/chess2img#readme",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"chess",
|
|
16
|
+
"chessboard",
|
|
17
|
+
"fen",
|
|
18
|
+
"pgn",
|
|
19
|
+
"png",
|
|
20
|
+
"image",
|
|
21
|
+
"chess-image",
|
|
22
|
+
"chess-render"
|
|
23
|
+
],
|
|
14
24
|
"type": "module",
|
|
15
25
|
"main": "./dist/index.cjs",
|
|
16
26
|
"module": "./dist/index.js",
|