/page2image

📷 page2image is a npm package for taking screenshot which also provides CLI command

Primary LanguageJavaScriptMIT LicenseMIT

📷 page2image

npm version Total downloads Build Status PRs Welcome MIT Licence

page2image is a npm package using Headless Chrome for taking screenshot which also provides CLI command

Using By Module 📦

Install

npm i page2image --save

Quick Examples

import Screenshot from 'page2image';

const screenshot = new Screenshot({
  waitUntil: 'networkidle',
  waitForFunction: function waitForFunction() {
    window.imageList = window.imageList || Array.from(document.getElementsByTagName('img'));

    return window.imageList.length <= window.imageList.reduce((loaded, imageElm) => (
      imageElm.complete ? loaded + 1 : loaded
    ), 0);
  },
  viewportConfig: { width: 1920, height: 1080 },
  screenshotConfig: { fullPage: true, path: 'screenshot.png' },
});

screenshot
  .takeScreenshot('https://github.com/Runjuu')
  .then(process.exit);

Methods

takeScreenshot(url:string)

Accept a url string as an argument and return an image Buffer

init(Config)

Accept a Config object and next time calling takeScreenshot will using new config to take screenshot

Config: {}


Using By CLI ⌨️

Install

npm i page2image --global

Quick Examples

# Single page
> page2image https://github.com/Runjuu --type=jpeg --quality=80

# Multi-page
> page2image https://github.com/Runjuu https://github.com/Runjuu --type=jpeg --quality=80

Config <argv>: <default value>

width: 1366

Page width in pixels.

height: 768

Page height in pixels, default will take a full page screenshot.

type: png

Specify screenshot type, could be either 'jpeg' or 'png'.

quality: 100

The quality of the image, between 0-100. Not applicable to png images.

dpr: 2

Specify device scale factor.

disableJS: false

Whether or not to disable JavaScript on the page.

waitUntil: networkidle

When to consider navigation succeeded. more details

sleep: 0

Wait ${sleep} milliseconds to take screenshot.



  • take screenshots via url
  • take screenshots from local html file

🤔 have any questions? 👉 new issues 😉