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

image-equal

v4.3.1

Published

Test if two images are equal, optionally show image difference

Downloads

8,472

Readme

image-equal unstable Build Status

Test if two images are equal. Useful for organising baseline tests for visual components.

Usage

npm install image-equal

let t = require('tape')
let equal = require('image-equal')
let pixels = require('image-pixels')

t('image test', async t => {
	t.ok(equal(await pixels('./a.png'), canvasA))
	t.ok(equal(await pixels('./b.png'), canvasB, {threshold: .2}))

	// display diff to console in case of mismatch
	t.ok(equal(await pixels('./c.png'), canvasC, true))

	// compare two pixel arrays
	t.ok(equal([0,0,0,255,255,255,255,255], [0,0,0,255,255,255,255,255]))

	t.end()
})

equal(imageA, imageB, diff?, threshold=0.1|options?)

Takes two images and returns true if they're similar and false otherwise, optionally sending diff stats to diff output. options can adjust comparison logic.

imageA, imageB

Shoud be actual image data container, one of:

  • Canvas, Context2D, WebGLContext
  • ImageData or Object {data: Uint8Array, width, height}
  • DataURL or base64 string
  • Image, Video, ImageBitmap with resolved data
  • Array, Array of Arrays, Uint8Array, FloatArray with raw pixels
  • ArrayBuffer, Buffer
  • Ndarray

To use async image source, like URL, path, ImageBitmap, Promise, incomplete Image/Video, Stream, Blob and alike, use image-pixels:

const equal = require('image-equal')
const load = require('image-pixels')
equal(await load('./a.png'), await load('./b.png')),

diff

Can be one of:

Type | Meaning ---|--- Bool | Show diff data to console, by default false. console | Send diff data to console, same as true. Canvas2D, Context2D | Put diff pixels to a canvas. document, Element | Create a canvas in document/element with diff pixels. filename String | Write diff data to a file or filepath. In browser downloads the file. ImageData | Write diff data to ImageData object. Array, TypedArray | Write diff pixels data to target array. Stream | Send data to stream, eg. process.stdout (acts the same as console). Function | Call function with diff data object. Object | Put diff stats into object: diff.data for diff pixels, diff.count for number of diff pixels, diff.ids for diff pixel ids and diff.amount for amount of difference between images, 0..1.

options

Property | Meaning ---|--- antialias | Include antialias, by default false. threshold | Sensitivity to px difference, 0 - intolerant, 1 - not sensitive. By default 0.1. clip | A sub-area to compare, rectangle [left, top, width, height].

See also

Credits

© 2018 Dmitry Yv. MIT License