I'm trying to use Resemble.js in node. I had a bit of trouble getting canvas/cairo installed (something to do with a mix of OS X Mavericks/XQuarts and Homebrew) but got there eventually.
Got pretty far, but I've hit a wall with this.
function ImageSimilarityChecker(){
var resemble = require("resemble").resemble;
var fs = require("fs");
var util = require("util");
this.admitImage = function(imagePath)
{
fs.readFile(imagePath, function (err, fileData)
{
if (err) throw err;
else
{
var api = resemble(fileData).onComplete(function(data){
console.log(imagePath);
console.log(util.inspect(data));
});
}
});
}
}
new ImageSimilarityChecker().admitImage("./public/images/test.jpg");
Results in this error:
/Users/pcoghill/Projects/imgManip/auth/Servers/Farm/node_modules/resemble/lib/server.js:38
context.drawImage(hiddenImage, 0, 0, width, height);
^
Error: Image given has not completed loading
at load (/Users/pcoghill/Projects/imgManip/auth/Servers/Farm/node_modules/resemble/lib/server.js:38:15)
at module.exports.loadImageData (/Users/pcoghill/Projects/imgManip/auth/Servers/Farm/node_modules/resemble/lib/server.js:11:7)
at Object.onComplete (/Users/pcoghill/Projects/imgManip/auth/Servers/Farm/node_modules/resemble/resemble.js:508:5)
at /Users/pcoghill/Projects/imgManip/auth/Servers/Farm/resembleFile.js:14:39
at fs.js:271:14
at Object.oncomplete (fs.js:107:15)
I'm pretty new to node, so I don't see how the image hasn't loaded. It's a local file and I'm handling it on the read completed callback (or so I think).
A little digging around makes me think this is an issue in canvas when reading jpg files, but I'm struggling to understand the details. I've found this question, which looks very similar, but I can't see how to convert this to my situation.
Could someone explain how I could fix this and what I'm doing wrong?