Skip to content
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

Image or Canvas expected when using in nodejs #53

Open
gpstmp opened this issue Aug 14, 2015 · 7 comments
Open

Image or Canvas expected when using in nodejs #53

gpstmp opened this issue Aug 14, 2015 · 7 comments

Comments

@gpstmp
Copy link

gpstmp commented Aug 14, 2015

Hi!
I'm trying to get imagediff work in nodejs but with no luck.
My code is pretty simple and looks like https://github.com/HumbleSoftware/js-imagediff/blob/master/bin/imagediff

var fs = require('fs'),
  imagediff = require('imagediff'),
  Canvas = require('canvas');

function loadImage (url, callback) {
  var image = new Canvas.Image();
  fs.readFile(url, function (error, data) {
    if (error) throw error;
    image.onload = function () {
      callback(image);
    };
    image.src = data;
  });
  return image;
}

var aName = 'test.png';

loadImage(aName, function (a) {
  var aData = imagediff.toImageData(a);
  console.log(" >>>>> equal: ", imagediff.equal(aData, aData));
});

But i got an error:

/vagrant/node_modules/imagediff/imagediff.js:126
    context.drawImage(image, 0, 0);
           ^
TypeError: Image or Canvas expected...

I have found related issue #38 but it gave me no new info about the problem.

I'm using:

  • "canvas": "1.2.7"
  • "imagediff": "1.0.8"
  • "node": "0.10.37"

I have tried to run imagediff command line tool and it is working as expected. I also noticed that imagediff uses old version of "canvas" (1.1.6) and have tried to use it in my project but with no success (have the same error).

Thanks for any help.

@cburgmer
Copy link
Contributor

I just run the following (your example + file from examples/1_normal_a.jpg):

var fs = require('fs'),
    imagediff = require('./imagediff'),
    Canvas = require('canvas');

function loadImage (url, callback) {
  var image = new Canvas.Image();
  fs.readFile(url, function (error, data) {
    if (error) throw error;
    image.onload = function () {
      callback(image);
    };
    image.src = data;
  });
  return image;
}

var aName = 'examples/1_normal_a.jpg';

loadImage(aName, function (a) {
  var aData = imagediff.toImageData(a);
  console.log(" >>>>> equal: ", imagediff.equal(aData, aData));
});

This prints

 >>>>> equal:  true

on Mac OSX with node v0.12.7, canvas 1.2.7 and the trunk version of imagediff.

Can you try rerunning with trunk + the above image to cross check?

@gpstmp
Copy link
Author

gpstmp commented Aug 14, 2015

Thanks for quick response. Yes, trunk version works as expected both with your image and mine. So, what is the problem? I see that trunk uses "canvas": "~1.2.7".

@cburgmer
Copy link
Contributor

I actually just pushed the version bump. You can see all the changes since 1.0.8 here:v1.0.8...master

@trajan-p
Copy link

I have the same issue. When reverting to imagediff v.1.0.6 it works fine though.

@chocochik92
Copy link

Still getting this issue as well, fixed it with "imagediff": "1.0.6" and "canvas": "1.2.7"

@cesutherland
Copy link
Member

@cburgmer think it's safe to bump to 1.0.9 with canvas 1.2.7 to resolve this?

@Mange
Copy link

Mange commented Oct 20, 2015

I'm also wondering this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants