Open
Description
Issue or Feature
- If this is an issue with installation, I have read the troubleshooting guide.
PID 14986 received SIGSEGV for address: 0x9bf00803
/home/pi/Discord-Bot/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x25f4)[0xf72df5f4]
/lib/arm-linux-gnueabihf/libc.so.6(__default_rt_sa_restorer+0x0)[0xf7b28db0]
/home/pi/Discord-Bot/node_modules/canvas/build/Release/canvas.node(_ZN9Context2d12PutImageDataERKN3Nan20FunctionCallbackInfoIN2v85ValueEEE+0x684)[0xf4c331b4]
/home/pi/Discord-Bot/node_modules/canvas/build/Release/canvas.node(+0x23db4)[0xf4c29db4]
Steps to Reproduce
const canvas = new Canvas.createCanvas();
const ctx = canvas.getContext('2d');
ctx.canvas.width = 1024;
ctx.canvas.height = 576;
const base = await Canvas.loadImage(avatarURL);
var hRatio = canvas.width / base.width;
var vRatio = canvas.height / base.height;
var ratio = Math.min(hRatio, vRatio);
var centerShift_x = (canvas.width - base.width * ratio) / 2;
var centerShift_y = (canvas.height - base.height * ratio) / 2;
ctx.drawImage(base, 0, 0, base.width, base.height, // source rectangle
centerShift_x, centerShift_y, base.width * ratio - 10, base.height * ratio - 10); // destination rectangle
var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
var pix = imgData.data;
//convert the image into a silhouette
for (var i = 0, n = pix.length; i < n; i += 4) {
//set red to 0
pix[i] = 0;
//set green to 0
pix[i + 1] = 0;
//set blue to 0
pix[i + 2] = 0;
//retain the alpha value
pix[i + 3] = pix[i + 3];
}
await ctx.putImageData(imgData, 0, 0);
canvas.toBuffer()
Your Environment
- Version of node-canvas (output of
npm list canvas
oryarn list canvas
): 2.9.0 - Environment (e.g. node 4.2.0 on Mac OS X 10.8): Raspberry Pi OS , Debian bullseye