const Jimp = require('jimp');
const canvas = new Jimp(512, 256, 0xFFFFFFFF);
// Promise-based wrapper for Jimp#getBuffer
function encode(image) {
return new Promise((fulfill, reject) => {
canvas.getBuffer(Jimp.MIME_PNG, (err, img) => err ? reject(err) : fulfill(img));
});
}
function makeIteratorThatFillsWithColor(color) {
return function (x, y, offset) {
this.bitmap.data.writeUInt32BE(color, offset, true);
}
};
// fill
canvas.scan(32, 32, 256, 128, makeIteratorThatFillsWithColor(0x00000040));
// border
const fillCrimson = makeIteratorThatFillsWithColor(0xED143DFF);
canvas.scan(236 , 100 , 240, 1, fillCrimson);
canvas.scan(236 , 100 + 110, 240, 1, fillCrimson);
canvas.scan(236 , 100 , 1 , 110, fillCrimson);
canvas.scan(236 + 240, 100 , 1 , 110, fillCrimson);
// displaying
await encode(canvas);