Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

TypeError: Image or Canvas expected #20

Open
rainer-maucher opened this issue Mar 11, 2014 · 4 comments
Open

TypeError: Image or Canvas expected #20

rainer-maucher opened this issue Mar 11, 2014 · 4 comments

Comments

@rainer-maucher
Copy link

Hi by executing:
node test.js
on a raspberry Pi with kittydar 1.6

where test.js contains the following JS:

var http = require('http'), fs = require('fs'),
Canvas = require('canvas');
kittyDar = require('kittydar');

fs.readFile('/var/www/kittenpush/web/images/userData/kittenimage.jpg', function(err, squid){
if (err) throw err;

img = new Canvas.Image;
img.src = squid;

var canvas = new Canvas(img.width, img.height);
var ctxxxx = canvas.getContext('2d');
ctxxxx.drawImage(img, 0, 0, img.width, img.height,0,0,img.width,img.height);

console.log(canvas);
var cats = kittyDar.detectCats(canvas);
console.log("there are", cats.length, "cats in this photo");
});

I'm ending up with an error insite the kittydar:

[Canvas 1600x1200]

/home/pi/node_modules/kittydar/kittydar.js:151
ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height,
^
TypeError: Image or Canvas expected
at resizeCanvas (/home/pi/node_modules/kittydar/kittydar.js:151:7)
at Object.kittydar.scaleCanvas (/home/pi/node_modules/kittydar/kittydar.js:96:14)
at Object.kittydar.getAllSizes (/home/pi/node_modules/kittydar/kittydar.js:81:28)
at Object.kittydar.detectCats (/home/pi/node_modules/kittydar/kittydar.js:56:24)
at /home/pi/test.js:19:23
at fs.js:266:14
at Object.oncomplete (fs.js:107:15)

Im not sure maybe im just missing something on creating my canvas, but it seems like the kittydar package looses the canvas during execution?

Has anyone else this issue? Would be glad if someone could help.

@chrissloey
Copy link

I've had the same issue previously and it turned out to be caused by using a newer version of node-canvas. Explicitly setting the correct versions in my package.json solved the issue for me:

"kittydar": "0.1.6",
"canvas": "1.0.1"

@rainer-maucher
Copy link
Author

Hi, ok i had adifferent canvas version, but unfortunately this didn't made the trick for me, could you maybe post your whole package.json ? Maybe there are more differences...
Just to make sure, even your node.js version would be great :)

@rainer-maucher
Copy link
Author

Mhm, sorry my mistake i the kittydar had the old canvas installation inside itsself... fixing this to the version you gave me solved the problem, it works now.

@girliemac
Copy link

I am using Pi too, with the latest Raspbian.

I had problem with node-canvas 1.0.1, so manually installed the latest, which gives me the same error.
However, as stated in Automattic/node-canvas#487,
I just point to the same node-canvas as a temporary fix, and everything is fine.

var kittydar = require('kittydar');
var Canvas = require('kittydar/node_modules/canvas');

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

No branches or pull requests

3 participants