-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getImageData not working for loaded image #787
Comments
|
I'm sorry, thank you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var Canvas = require('canvas')
var Image = Canvas.Image;
var fs = require('fs');
fs.readFile(__dirname + '/img/image.png', function(err, data){
if (err) throw err;
var img = new Image();
img.onload = function(){
var canvas = new Canvas(img.width, img.height);
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, img.width, img.height);
var imageData = ctx.getImageData();
}
img.src = data;
});
// LOG BELOW
var imageData = ctx.getImageData();
^
Error: IndexSizeError: The source width is 0.
at Error (native)
at img.onload (/MyProject/test.js:12:25)
at Image.src (/MyProject/node_modules/canvas/lib/image.js:30:17)
at /MyProject/index.js:40:11
at FSReqWrap.readFileAfterClose as oncomplete
The text was updated successfully, but these errors were encountered: