Question

I'm using the request and node-canvas modules to try and download and process an image:

var request = require('request');
var Image = require('canvas').Image;

var url = 'http://farm8.staticflickr.com/7333/11286633486_070f0d33bc_n.jpg';

request.get({ url: url, encoding: null }, function(err, res, body) {
    if (err) throw err;

    var image = new Image();

    image.onerror = function() {
        console.error(arguments);
    };

    image.onload = function() {
        console.log('loaded image');
    };

    image.src = new Buffer(body, 'binary');
});

I get the error 'Error: error while reading from input stream' (the onerror event is fired). But when I hit the above image URL in a browser, it displays the image as expected.

What am I doing wrong?

Was it helpful?

Solution

Fixed it!

Seems I had a corrupted install of pixman and/or cairo on OSX (dependencies of node-canvas), probably because I tried to install them via homebrew.

The solution was to get rid of them from homebrew using:

brew uninstall cairo
brew uninstall pixman

...then run:

brew doctor

..to check for any broken symlinks etc. related to cairo and pixman. Then you have to manually delete any cairo & pixman bins/libs/symlinks etc. using Finder.

Next, follow the install instructions for node-canvas to reinstall cairo and pixman on OSX.

Finally, you'll probably need to reinstall node-canvas via npm, so navigate to your 'node_modules' folder and delete the 'canvas' dir. Then run:

npm install canvas
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top