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 = 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;
as well as promise-style:
screenshot;
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;
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 = ; screenshot;
License
MIT
Copyright © 2015 Level Seven