node-webshot
node-webshot copied to clipboard
Using Node-Webshot with Sharp (image resize)
trafficstars
Hi guys,
Any tips how I can resize stream produced by node-webshot with sharp (http://sharp.dimens.io/en/stable/api/)?
Here is example how screenshot is rendered:
var renderStream = webshot("http://localhost:1337/template/00001/", null, {
screenSize: {
width: 620,
height: 400
},
shotSize: {
width: 620,
height: 400
},
quality: 100
}),
screenshot = '';
// Capture the streaming output from the screenshot
renderStream.on('data', function (data) {
screenshot += data.toString('binary');
});
// Once the image capture is completed, write it out to the browser
renderStream.on('end', function () {
// sharp should be used here
res.set('Content-Type', 'image/png');
res.end(screenshot, 'binary');
});
Any solution for this? I need the same
const chunks = []
renderStream.on('data', function(chunk) {
chunks.push(chunk);
})
renderStream.on('end', () => {
sharp(Buffer.concat(chunks))
.resize(600, 600)
convert to format you need
})