From ea5ff8e2f945e278d2a56d24ed6ff42963345654 Mon Sep 17 00:00:00 2001 From: Eric Burel Date: Mon, 5 Sep 2016 12:31:20 +0200 Subject: [PATCH] Update README.md Add an example with `Buffer`, as they can be useful in many cases (uploading to S3, sending a email with an inline image and so on). --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 44b4e06..0efc93f 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,27 @@ renderStream.on('data', function(data) { }); ``` +An example using a buffer to store the image temporarily instead of a file: + +```javascript +var webshot = require('webshot'); +var fs = require('fs'); +var lwip = require('lwip'); + +var renderStream = webshot('google.com'); +var buffer = new Buffer('') + +renderStream.on('data', function(data) { + buffer = concat([buffer, data]) +}); +renderStream.on('end', function(){ + // do whatever you want with your buffer + fs.writeFileSync('/my-folder/my-image.png', buffer, {encoding:'base64'}) // save it as file + console.log('My Screenshot') // print the inline html image code + lwip.open(buffer, 'png', function(err, image){}) // open it for further modification using lwip +} +``` + An example showing how to take a screenshot of a site's mobile version: ```javascript