Skip to content

Image or Canvas expected when using in nodejs #53

Open
@gpstmp

Description

@gpstmp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions