Giter VIP home page Giter VIP logo

node-screenshots's Introduction

📸 node-screenshots

node-screenshots is a native node.js screenshot library that supports Mac, Windows, and Linux systems without any dependencies.

English | 简体中文

Support Matrix

Operating System

Operating System node14 node16 node18
Windows x64
Windows x32
Windows arm64
macOS x64
macOS arm64
Linux x64 gnu
Linux x64 musl

Example

const fs = require("fs");
const { Screenshots } = require("node-screenshots");

let capturer = Screenshots.fromPoint(100, 100);

console.log(capturer, capturer.id);

// Synchronous capture
let image = capturer.captureSync();
fs.writeFileSync("./a.png", image);

// Asynchronous capture
capturer.capture().then((data) => {
    console.log(data);
    fs.writeFileSync(`${capturer.id}.png`, data);
});

// Get all screen captures
let all = Screenshots.all() ?? [];

all.forEach((capturer) => {
    console.log({
        id: capturer.id,
        x: capturer.x,
        y: capturer.y,
        width: capturer.width,
        height: capturer.height,
        rotation: capturer.rotation,
        scaleFactor: capturer.scaleFactor,
        isPrimary: capturer.isPrimary,
    });
    capturer.captureSync(true);
});

API

  • Screenshots.fromPoint(x, y): Get a screenshot from the specified coordinates
  • Screenshots.all(): Get all screenshots
  • screenshots.capture(copyOutputData): Asynchronously capture full screen
  • screenshots.captureSync(copyOutputData): Synchronously capture full screen
  • screenshots.captureArea(x, y, width, height, copyOutputData): Asynchronously capture the specified area
  • screenshots.captureAreaSync(x, y, width, height, copyOutputData): Synchronously capture the specified area

copyOutputData: pass related parameters in electron, otherwise electron will crash, nodejs does not pass or passes false, performance will be better, for more information refer to napi-rs/napi-rs#1346

Linux System Requirements

On Linux, you need to install libxcb, libxrandr, and dbus.

Debian / Ubuntu:

apt-get install libxcb1 libxrandr2 libdbus-1-3

Alpine:

apk add libxcb libxrandr dbus

node-screenshots's People

Contributors

nashaofu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.