node-screenshot-machine
v1.0.2
Published
Simple node.js wrapper for Screenshot Machine's API
Downloads
3
Readme
Simple node.js wrapper for Screenshot Machine's API.
API
Screenshot Machine provides a very simple url-based API, with config options passed as optional url params. This library provides a convenient, node-ish wrapper that makes using Screenshot Machine in your node app a snap.
Installation
Run npm install node-screenshot-machine
or git clone
then npm install
Optionally run unit tests: npm test
Setup
Initializing the node-screenshot-machine module is simple:
var screenshot = require('node-screenshot-machine')({
key: ***** // your screenshotmachine API key
});
Capture
Capturing a website screenshot is also simple:
screenshot.get(options, callback);
The module handles standard callback-style invocation:
screenshot.get({
url: 'www.test.com'
},
function(err, result){
if (err) {
// handle error
}
// handle result
});
as well as promise-style:
screenshot.get({
url: 'www.test.com'
})
.then(function(result){
// handle result
})
.catch(function(err){
// handle error
});
For ease of use, you can also simply pass in a url string, which will capture a screenshot using the default settings (or any settings passed in during setup):
screenshot.get('www.test.com')
.then(function(result){
// handle result
})
.catch(function(err){
// handle error
});
Options
These are all the options supported by the .get
method (complete details can be found in Screenshot Machine's API guide):
Required
- url: The web page to capture a screenshot for
Optional
- size: Captured image size (defaults to 'T' - 120 x 90px)
- format: Image file format (defaults to 'JPG')
- hash: MD5 hash used for security purposes when called from a web page (defaults to blank)
- cacheLimit: How many days to allow images from cache (defaults to 14 days)
- timeout: Capture timeout (defaults to 200ms)
Streaming
Note that the screenshot.get
method optionally supports streaming the captured image directly to any writable stream using the optional writeStream
option:
var imageFileStream = require('fs').createWriteStream('siteImage.png');
screenshot.get({
url: 'www.someurl.com',
format: 'PNG',
writeStream: imageFileStream
});
License
MIT
Copyright © 2015 Level Seven