Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pixel-change

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pixel-change

Measure differences between 2 identically sized buffer arrays of gray, rgb, or rgba pixels.

  • 0.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
increased by10.35%
Maintainers
1
Weekly downloads
 
Created
Source

pixel-change

Build Status Build status GitHub issues GitHub license

EXPERIMENTAL. FIRST ATTEMPT AT USING N-API WHICH IS ONLY SUPPORTED ON NODE 8.5 AND UP

Measure differences between 2 identically sized buffer arrays of gray, rgb, or rgba pixels. Backed by c++ libraries iterating pixel buffers, converting to grayscale, measuring differences, and reporting back the percent of pixels that have changed.

installation

npm install pixel-change

usage


const PixelChange = require('pixel-change');

/* -- access static methods -- */

//will return a percent of how many gray pixels are changed between the 2 buffer pixel arrays
const percent = PixelChange.compareGrayPixels(width, height, diff, buffer1, buffer2);

//will return a percent of how many rgb pixels are changed between the 2 buffer pixel arrays
const percent = PixelChange.compareRgbPixels(width, height, diff, buffer1, buffer2);

//will return a percent of how many rgba pixels are changed between the 2 buffer pixel arrays
const percent = PixelChange.compareRgbaPixels(width, height, diff, buffer1, buffer2);

/* -- access instance methods -- */

//create a new instance to access convenience methods
const pc = new PixelChange({width: 1920, height: 1080, depth: 3, diff: 25, percent: 12});

//listen to change event when percent of different pixels is detected
pc.on('change', (percent)=>{
    //do something when change event is dispatched because of percent
});

//compare 2 buffers, will dispatch event if change is detected
pc.compare(buffer1, buffer2);

//alternate convenience method, keep feeding pixel buffer via push
//instance will cache previous buffer to compare with next one pushed
pc.push(buffer);

/* -- alternative to listening to "change" event

//pass callback to new instance
const pc = new PixelChange({width: 1920, height: 1080, depth: 3, diff: 25, percent: 12}, (err, percent)=>{
    if (err) {
        throw err;
    }
    //do something when callback is called with percent
});

Keywords

FAQs

Package last updated on 06 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc