I have view all related issues, but do not find answer. When i'm using this code in node.js:
var canvas = new global.canvas(400, 400), ctx = canvas.getContext('2d');
global.fs.readFile('test.png', function (err, data) {
if (!err) {
var base_image = new global.canvas.Image;
base_image.src = data;
ctx.drawImage(base_image, 0, 0, 100, 100);
}
else
console.log(err);
});
I'm getting error: Image given has not completed loading When i'm add onload event, like this:
base_image.onload = function () {
ctx.drawImage(base_image, 0, 0, 100, 100);
}
It's never fires at all. Please help me to find answer.
Instead of
img.src = buffer
img.onload = function(){ ... }
do the following:
img.onload = function(){ ... }
img.src = buffer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With