npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

win-screenshot

v1.0.4

Published

A mighty, robust screenshot library for Windows, Electron and Node.JS Developers

Downloads

11

Readme

Windows Screenshot Library for JS Lovers

:rocket: :telescope: A mighty, robust screenshot library for Windows, Electron and Node.JS Developers.

Install

$ npm i win-screenshot

Screenshot type offered by this library:

  1. Coordinate Based or Specific Region (x1, y1, x2, y2)
  2. Full Screen
  3. Windows Working Area only (taskbar is excluded)
  4. Only Taskbar
  5. All Active Windows at once

What so special about this library:

  1. It is capable of finding accurate coordinates of an Active Window or Taskbar irrespective of the taskbar location (BOTTOM, LEFT, TOP, RIGHT) on the screen.
  2. This is a Node.JS library but some part of the backend is developed using C#, which is useful for invoking Windows native methods easily.
  3. All Active Windows can be screenshotted at once automatically just by calling a single method.
  4. This library supports various image formats to save your screenshot in. (GIF, JPEG, PNG, TIFF).

Note:

  1. This library has a limitation for taking screenshots of only primary monitor/screen.
  2. It requires .NET Framework 3.5 Client Profile as it is build upon C# Code.

Screenshot all active windows:

// ES6 Destructuring Assignment
const { Screenshot, ImageFormat } = require('win-screenshot');
const { writeFileSync } = require('fs');
const { homedir } = require('os');
const { spawnSync } = require('child_process');

// Destination Directory
const directoryName = `${homedir()}\\Desktop`;

Screenshot.captureAllWindows({
    
    // Use of PNG format for taking screenshot
    imageFormat: ImageFormat.PNG

}).then(response => {

    // This is necessary as the response of captureAllWindows() is an array
    response.forEach(obj => {
        // Now obj contains an element from the array
        // You need to convert encoded base64 string into buffer before writing
        // This will save each screenshot with its process name.
        writeFileSync(`${directoryName}\\${obj.processName}.png`, Buffer.from(obj.imageBuffer, 'base64'));
    })

    // This will open the destination directory using cmd as inter-process communication call,
    // once all screenshots are done writing
    spawnSync("cmd.exe", ["/c", `start ${directoryName}`]);
});

Screenshot using given coordinates:

// ES6 Destructuring Assignment
const { Screenshot, ImageFormat } = require('win-screenshot');
const { writeFileSync } = require('fs');
const { homedir } = require('os');
const { spawnSync } = require('child_process');

// Absolute File Path
let fileName = `${homedir()}\\Desktop\\Coordinates Image.jpg`;

Screenshot.captureByCoordinates({

    // Pass coordinates like this
    coords: {
        x1: 50,
        y1: 50,
        x2: 400,
        y2: 400
    },
    // Use of JPEG format for taking screenshot
    imageFormat: ImageFormat.JPEG

}).then(response => {
    
    // You need to convert encoded base64 string into buffer before writing
    // This will save the screenshot with the specified file name.
    writeFileSync(fileName, Buffer.from(response.imageBuffer, 'base64'));

    // This will show the saved screenshot with a blue selection in an explorer window
    // using cmd as inter-process communication call,
    // once the file is done writing
    spawnSync("cmd.exe", ["/c", `explorer.exe /select, ${fileName}`]);
});

Screenshot of fullscreen:

// ES6 Destructuring Assignment
const { Screenshot, ImageFormat } = require('win-screenshot');
const { writeFileSync } = require('fs');
const { homedir } = require('os');
const { spawnSync } = require('child_process');

// Absolute File Path
let fileName = `${homedir()}\\Desktop\\Fullscreen Image.png`;

Screenshot.captureFullScreen({

    // Use of PNG format for taking screenshot
    imageFormat: ImageFormat.PNG

}).then(response => {

    // You need to convert encoded base64 string into buffer before writing
    // This will save the screenshot with the specified file name.
    writeFileSync(fileName, Buffer.from(response.imageBuffer, 'base64'));

    // This will show the saved screenshot with a blue selection in an explorer window
    // using cmd as inter-process communication call,
    // once the file is done writing
    spawnSync("cmd.exe", ["/c", `explorer.exe /select, ${fileName}`]);
});

Screenshot of taskbar:

// ES6 Destructuring Assignment
const { Screenshot, ImageFormat } = require('win-screenshot');
const { writeFileSync } = require('fs');
const { homedir } = require('os');
const { spawnSync } = require('child_process');

// Absolute File Path
let fileName = `${homedir()}\\Desktop\\Taskbar Image.gif`;

Screenshot.captureTaskbar({

    // Use of GIF format for taking screenshot
    imageFormat: ImageFormat.GIF

}).then(response => {

    // You need to convert encoded base64 string into buffer before writing
    // This will save the screenshot with the specified file name.
    writeFileSync(fileName, Buffer.from(response.imageBuffer, 'base64'));

    // This will show the saved screenshot with a blue selection in an explorer window
    // using cmd as inter-process communication call,
    // once the file is done writing
    spawnSync("cmd.exe", ["/c", `explorer.exe /select, ${fileName}`]);
});

Screenshot of working area of windows:

// ES6 Destructuring Assignment
const { Screenshot, ImageFormat } = require('win-screenshot');
const { writeFileSync } = require('fs');
const { homedir } = require('os');
const { spawnSync } = require('child_process');

// Absolute File Path
let fileName = `${homedir()}\\Desktop\\Working Area Image.tiff`;

Screenshot.captureWorkingArea({

    // Use of TIFF format for taking screenshot
    imageFormat: ImageFormat.TIFF

}).then(response => {

    // You need to convert encoded base64 string into buffer before writing
    // This will save the screenshot with the specified file name.
    writeFileSync(fileName, Buffer.from(response.imageBuffer, 'base64'));

    // This will show the saved screenshot with a blue selection in an explorer window
    // using cmd as inter-process communication call,
    // once the file is done writing
    spawnSync("cmd.exe", ["/c", `explorer.exe /select, ${fileName}`]);
});