node.js - NodeJS No image returned when trying to convolve image with sharp -


i trying apply sobel filter image detect edges. don't know doing - i'm experimenting.

i'm trying add convolve operator image using sharp (https://github.com/lovell/sharp), see below:

sharp(body)     .resize(1000)     .greyscale()     .convolve({         width: 3,         height: 3,         kernel: [-1, 0, 1, -2, 0, 2, -1, 0, 1]      })     .webp()     .tobuffer(function(err, buffer) {         res.end(buffer, 'binary');   }); 

when add .convolve() operation don't see image returned. when remove image usual. doing documentation seems suggesting http://sharp.readthedocs.io/en/stable/api/

what doing wrong?


edit: error getting [error: im_local_dmask: nonsense mask parameters] when console.log(err) before res.end()

turns out issue when values in kernel added 0 needed add

scale: 1

to kernel object , works fine. not sure if bug or misleading documentation. see:

https://github.com/lovell/sharp/issues/561


with below code works fine:

sharp(body)     .resize(1000)     .greyscale()     .convolve({         width: 3,         height: 3,         kernel: [-1, 0, 1, -2, 0, 2, -1, 0, 1],         scale: 1      })     .webp()     .tobuffer(function(err, buffer) {         res.end(buffer, 'binary');   }); 

Comments