Sunday 21 May 2017

ResembleJS TypeError: hiddenImage.setAttribute is not a function

I am experimenting with image to image comparison with Resemble.js, and I have run into an error I don't know how to get past. I have the canvas dependency installed and my console logs are showing the image dimensions. the Resemble.js line is triggering

hiddenImage.setAttribute('crossorigin', 'anonymous');
TypeError: hiddenImage.setAttribute is not a function

in the console. I have tried searching for the error and found this issue that has been closed by the Resemble.js team, but I don't know why it is triggering for me.

I am new to Node.js in general, and maybe I am missing something else. If anybody could help me out I would be so grateful! Below is the code I am working with. I got to this point by piecing together info from the Resemble.js github, the Node-canvas github, and various stackoverflow searches when I ran into problems.

var fs = require('fs');
var resemble = require('resemblejs');
var Canvas = require('canvas');     

app.get('/test', function(req, res) {
    fs.readFile('me.jpg', function(err, data) {
        if (err) console.log(err);
        var me = new Canvas.Image();
        me.src = data;
        console.log(me);
//console prints: [Image:200x200 complete]
        fs.readFile('boxer.jpg', function(err, data) {
            if (err) console.log(err);
            var boxer = new Canvas.Image();
            boxer.src = data;
                console.log(boxer);
//console prints: [Image:632x629 complete]
            resemble(me).compareTo(boxer).onComplete(function(data) {
                console.log(data.misMatchPercentage);
            });
            res.send('done');
        });
    });
});



via sara

No comments:

Post a Comment