andyruwruw / chess-image-generator

Accepts FEN, PGN or array data for chess board and generates PNG or buffer.
https://www.npmjs.com/package/chess-image-generator
MIT License
55 stars 22 forks source link

use Canvas#toBuffer() instead #10

Open jimmywarting opened 3 years ago

jimmywarting commented 3 years ago

Drop this lib https://github.com/andyruwruw/chess-image-generator/blob/e885ef1ceecb4364fdf2aeb5758604e6d3b044ee/src/chess-image-generator.js#L5

it will work much faster

pi0neerpat commented 2 years ago

Just did some testing on this, and didn't see any performance improvements. It might have been my implementation, but I actually saw a 100ms increase. You still need canvas, since canvas-to-buffer doesn't include tooling for createCanvas or loadImage. The latter could be abstracted away using svgs, but the former will always be needed. eg:

const { createCanvas, loadImage } = require("canvas");
const Frame = require("canvas-to-buffer");

const canvas = createCanvas(this.size, this.size);
// ... all the existing code

// Output
const frame = new Frame(canvas);
return frame.toBuffer();