webpage-capture v0.2.2
webpage-capture
A super simple way to capture webpages screenshots using phantomjs.
Installation
If you want to use it inside your scripts, save and install it in your project dependencies.
npm install --save webpage-capture
yarn add webpage-capture
Once it has done you can require webpage-capture in your script and start using it.
Global module
You can also use it as a cli-tool installing it as a global module:
npm install -g webpage-capture
yarn global add webpage-capture
Than you can start playing around with the options using the built-in help typing: -h, --help
Usage
The most basic use is with a single input and default settings:
const webCapture = require('webpage-capture');
webCapture('https://github.com/b4dnewz', {}, (err, res) => {
// handle err
console.log('Output saved to:', res);
});
You can also capture multiple source urls:
const webCapture = require('webpage-capture');
webCapture([
'https://github.com/b4dnewz',
'https://github.com/b4dnewz/webpage-capture'
], {}, (err, res) => {
// handle err
console.log('Output saved to:', res);
});
Or render HTML text and capture it:
const webCapture = require('webpage-capture');
webCapture('<h1>this is c00l</h1>', {}, (err, res) => {
// handle err
console.log('Output saved to:', res);
});
It can also render the same source in multiple viewports resolutions:
const webCapture = require('webpage-capture');
webCapture('https://github.com/b4dnewz', {
viewport: ['desktop', 'laptop-mdpi', 'nexus-7']
}, (err, res) => {
// handle err
console.log('Output saved to:', res);
});
It can accept many options to customize the capturing behavior:
const webCapture = require('webpage-capture');
const options = {
debug: false,
outputDir: './output',
outputType: 'file',
whiteBackground: true,
renderOptions: {
format: 'png',
quality: 80
},
crop: false,
clipRect: {
top: 0,
left: 0
},
viewport: 'desktop',
userAgent: 'random'
};
webCapture('https://github.com/b4dnewz', options, (err, res) => {
// handle err
console.log('Output saved to:', res);
});
Options
outputDir
Type: String
Default value: ./output
Where to save the files in case of 'file' outputType.
outputType
Type: String
Default value: file
The capture output type that can be: file, base64 or html.
renderOptions
Type: Object
Default value: {
format: 'png',
quality: 80
}
The options to pass to phantomjs page renderer.
crop
Type: Object
Default value: false
If true the screenshot will be cropped as viewportSize.
userAgent
Type: string
Default value: random
Let select the user agent to use, by default is a random browser user agent.
debug
Type: Boolean
Default value: false
If enabled show extra execution logs useful when debugging.
whiteBackground
Type: Boolean
Default value: true
Force the pages to have a white background color.
viewportSize
Type: Object
Default value: {
width: 1280,
height: 800
}
The default page viewportSize for phantomjs.
License
MIT © Filippo Conti
Contributing
- Create an issue and describe your idea
- Fork the project (https://github.com/b4dnewz/webpage-capture/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Write some tests and run it (
npm run test'
) - Publish the branch (
git push origin my-new-feature
) - Create a new Pull Request
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago