Welcome to pageres: Your Ultimate Screenshot Tool
Are you looking for a reliable and efficient way to capture screenshots of websites? Look no further than pageres. This powerful library allows developers to take screenshots of web pages from the command line with ease. Whether you’re generating preview images for blogs, capturing visual regression tests, or archiving web pages, pageres has got you covered.
Getting Started with pageres
First, you’ll need to install pageres. You can do this using npm:
npm install -g pageres
How to Use pageres
You can use pageres directly from the command line to take simple screenshots:
pageres https://example.com
This command will capture a screenshot of the webpage at the specified URL and save it to your current directory.
Customizing Your Screenshots
Pageres offers a variety of options to customize your screenshots. Here are a few examples:
Specify Resolution
pageres example.com 1366x768
Capture a screenshot at the specified resolution.
Capture Multiple Resolutions
pageres example.com 1024x768 800x600
Capture screenshots at multiple resolutions.
Delay Capture
pageres example.com --delay=5
Delay the screenshot capture by a specified number of seconds to allow the page to fully load.
Save Screenshots to a Specific Directory
pageres example.com --dest=~/screenshots
Save the captured screenshot to a specific directory.
Capture Full-Page Screenshots
pageres --crop=false example.com
Capture the entire web page, not just the visible part.
Authentication
pageres example.com --username=yourUsername --password=yourPassword
Capture screenshots of pages that require basic authentication.
Developing an Application with pageres
Now, let’s create a simple Node.js application using pageres to capture and save screenshots.
First, create a new Node.js project and install pageres:
npm init -y
npm install pageres
Next, create an index.js
file and add the following code:
const Pageres = require('pageres');
(async () => {
const pageres = new Pageres({ delay: 2 })
.src('example.com', ['1280x1024', '1920x1080'], { crop: true })
.dest(__dirname);
await pageres.run();
console.log('Screenshots captured and saved to', __dirname);
})();
This script will capture screenshots of example.com
at the specified resolutions and save them to the project directory.
With pageres, the possibilities are endless! Leverage its powerful features to enhance your web development workflow and create captivating screenshots effortlessly.
Hash: e87eb9c00bda40caa4fbd7bc1d6172642a07e9545ac26507a861dc546146f3c4