EyalAr / lwip

Light Weight Image Processor for NodeJS
MIT License
2.36k stars 231 forks source link

Doesn't work with downloaded buffer #271

Closed cihadturhan closed 8 years ago

cihadturhan commented 8 years ago

Here is my code:

request = require('request')
lwip = require('lwip');

request.get( { url: 'http://www.bing.com/az/hprichbg/rb/MatterhornVideo_EN-US10200962750_320x180.jpg', encoding: 'binary'}, function ( err, response, body ) {
    console.log(body);
    // obtain an image object:
    lwip.open(body, 'jpeg', function(err, image){
        console.log(err);
      // check err...
      // define a batch of manipulations and save to disk as JPEG:
      image.batch()
        .resize(32, 18)      // scale to 75%
        .blur(5)              // Gaussian blur with SD=5
        .writeFile('output.jpg', function(err){
          console.log(err);
        });

    });
})

It throws the following error: [Error: Path must be a string without null bytes.]

I checked the buffer with console.log, and it prints a garbled string - because it's a binary - so I see binary data is not null.

Could anyone tell me what's wrong?

nabilfreeman commented 8 years ago

hey @cihadturhan, try setting encoding: null - that should definitely return a buffer from request.

i am guessing that lwip interprets any String it finds as a filename.

EyalAr commented 8 years ago

That's right, body needs to be an instance of Buffer.