I get buffer data to my program from external and I want to process buffer data and send it as a buffer also. So I don't want to convert buffer into an image. How can I do this?
I try this way but it not work.
const process = await sharp(incoming_buffer_data).grayscale();
fs.writeFileSync('test.jpg', process); // I am using this for testing. Allways I am getting worng image format as an error
Assuming incoming_buffer_data is indeed a buffer and has a supported image format.
You can either get the output as buffer, and send it to fs.writeFileSync() like you tried to do
const buffer = await sharp(incoming_buffer_data).grayscale().toBuffer();
fs.writeFileSync('test.jpg', buffer);
Or you can write it to a file directly
await sharp(incoming_buffer_data).grayscale().toFile('test.jpg');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With