Node.js - Loading and processing an image using "request" and "node -canvas"

I use request and node - canvas to try to load and process the 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 an error ' Error: error while reading from input stream' (onerror event fired). But when I hit the above image URL in the browser, it displays the image as expected.

What am I doing wrong?

+4
source share
1 answer

Corrected!

It seems that I had a damaged installation of pixman and / or cairo on OSX (dependency on node -canvas), probably because I was trying to install them through homebrew.

, , :

brew uninstall cairo
brew uninstall pixman

... :

brew doctor

.. .., cairo pixman. cairo pixman/libs/symlinks .. Finder.

node -canvas, cairo pixman OSX.

, , , node -canvas npm, "node_modules" "canvas". :

npm install canvas
-1

Source: https://habr.com/ru/post/1524401/


All Articles