chess2img 0.4.0 → 0.4.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/README.md +78 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
|
|
16
16
|
`chess2img` renders chessboard PNG, SVG, and JPEG images from FEN, PGN, or board-array inputs with a small Promise-based API for JavaScript and TypeScript users on Node.js.
|
|
17
17
|
|
|
18
|
+
Supported output formats:
|
|
19
|
+
|
|
20
|
+
- PNG
|
|
21
|
+
- SVG
|
|
22
|
+
- JPEG
|
|
23
|
+
|
|
18
24
|
## Features
|
|
19
25
|
|
|
20
26
|
- Render PNG, SVG, or JPEG chessboard images from `fen`, `pgn`, or `board` input.
|
|
@@ -118,10 +124,40 @@ await renderFile("board.png", {
|
|
|
118
124
|
|
|
119
125
|
`renderChess(...)` and `renderFile(...)` are the explicit PNG APIs.
|
|
120
126
|
|
|
127
|
+
### Direct PNG, SVG, And JPEG Buffers
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { renderChess, renderJpeg, renderSvg } from "chess2img";
|
|
131
|
+
|
|
132
|
+
const png = await renderChess({
|
|
133
|
+
fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1",
|
|
134
|
+
size: 480,
|
|
135
|
+
style: "merida",
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const svg = await renderSvg({
|
|
139
|
+
fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1",
|
|
140
|
+
size: 480,
|
|
141
|
+
style: "merida",
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const jpeg = await renderJpeg({
|
|
145
|
+
fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1",
|
|
146
|
+
size: 480,
|
|
147
|
+
style: "merida",
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
121
151
|
### SVG And JPEG File Helpers
|
|
122
152
|
|
|
123
153
|
```ts
|
|
124
|
-
import { renderJpegFile, renderSvgFile } from "chess2img";
|
|
154
|
+
import { renderFile, renderJpegFile, renderSvgFile } from "chess2img";
|
|
155
|
+
|
|
156
|
+
await renderFile("board.png", {
|
|
157
|
+
fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1",
|
|
158
|
+
size: 480,
|
|
159
|
+
style: "merida",
|
|
160
|
+
});
|
|
125
161
|
|
|
126
162
|
await renderSvgFile("board.svg", {
|
|
127
163
|
fen: "4k3/8/8/8/8/8/8/4K3 w - - 0 1",
|
|
@@ -236,11 +272,24 @@ const generator = new ChessImageGenerator({
|
|
|
236
272
|
await generator.loadPGN("1. e4 e5 2. Nf3 Nc6 3. Bb5 a6");
|
|
237
273
|
generator.setHighlights(["e4", "e5"]);
|
|
238
274
|
|
|
275
|
+
const png = await generator.toBuffer();
|
|
276
|
+
const svg = await generator.toSvg();
|
|
277
|
+
const jpeg = await generator.toJpeg();
|
|
278
|
+
|
|
239
279
|
await generator.toFile("board.png");
|
|
240
280
|
await generator.toSvgFile("board.svg");
|
|
241
281
|
await generator.toJpegFile("board.jpg");
|
|
242
282
|
```
|
|
243
283
|
|
|
284
|
+
Class method summary:
|
|
285
|
+
|
|
286
|
+
- `toBuffer()` -> PNG `Buffer`
|
|
287
|
+
- `toFile(path)` -> writes PNG
|
|
288
|
+
- `toSvg()` -> SVG `string`
|
|
289
|
+
- `toSvgFile(path)` -> writes SVG
|
|
290
|
+
- `toJpeg()` -> JPEG `Buffer`
|
|
291
|
+
- `toJpegFile(path)` -> writes JPEG
|
|
292
|
+
|
|
244
293
|
### JavaScript Usage
|
|
245
294
|
|
|
246
295
|
```js
|
|
@@ -271,7 +320,7 @@ Bundled built-in themes:
|
|
|
271
320
|
|
|
272
321
|
Built-in themes are vendored in-package and render through the same theme pipeline as custom themes.
|
|
273
322
|
|
|
274
|
-
## Custom
|
|
323
|
+
## Custom Piece Packs
|
|
275
324
|
|
|
276
325
|
Register a reusable theme globally:
|
|
277
326
|
|
|
@@ -294,11 +343,37 @@ Or pass either:
|
|
|
294
343
|
- a registered custom theme name through `theme: "custom-theme"`
|
|
295
344
|
- an inline `ThemeDefinition` object through `theme: { ... }`
|
|
296
345
|
|
|
297
|
-
Custom
|
|
346
|
+
Custom piece packs may use either:
|
|
298
347
|
|
|
299
348
|
- `svg` assets
|
|
300
349
|
- `png` assets
|
|
301
350
|
|
|
351
|
+
Expected piece-pack structure:
|
|
352
|
+
|
|
353
|
+
```text
|
|
354
|
+
my-pack/
|
|
355
|
+
wK.svg
|
|
356
|
+
wQ.svg
|
|
357
|
+
wR.svg
|
|
358
|
+
wB.svg
|
|
359
|
+
wN.svg
|
|
360
|
+
wP.svg
|
|
361
|
+
bK.svg
|
|
362
|
+
bQ.svg
|
|
363
|
+
bR.svg
|
|
364
|
+
bB.svg
|
|
365
|
+
bN.svg
|
|
366
|
+
bP.svg
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
You can point the theme definition at either SVG or PNG files. Mixing formats is also supported as long as all 12 canonical pieces are present.
|
|
370
|
+
|
|
371
|
+
### Example Third-Party Packs
|
|
372
|
+
|
|
373
|
+
- `chess.com-boards-and-pieces`: https://github.com/GiorgioMegrelli/chess.com-boards-and-pieces
|
|
374
|
+
|
|
375
|
+
These are third-party repositories. They are not bundled with `chess2img`, and you should verify each pack's license terms before redistribution or repackaging.
|
|
376
|
+
|
|
302
377
|
## API
|
|
303
378
|
|
|
304
379
|
### Public Exports
|