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 🙏

© 2026 – Pkg Stats / Ryan Hefner

png-visual-compare

v4.1.0

Published

Node.js utility to compare PNG files or their areas

Readme

png-visual-compare

🎯 Visual regression testing for PNG images with zero binary dependencies

npm version npm downloads Tests License


A Node.js utility to compare PNG images or their areas without binary and OS dependencies.

Key Benefits:

  • Zero Native Binaries — Pure JavaScript, works everywhere
  • 🖼️ File or Buffer — Accept absolute file paths or raw Buffer inputs
  • 🔍 Pixel-Level Accuracy — Powered by pixelmatch
  • 🎭 Exclusion Zones — Skip regions during comparison with excludedAreas
  • 🗂️ Diff Output — Optionally write a diff PNG with highlighted mismatches
  • 💪 TypeScript Support — Full type definitions included

Table of Contents


Installation

npm install -D png-visual-compare

Node.js Requirement: Node.js 20 or higher is required.


Quick Start

import { comparePng } from 'png-visual-compare';

const mismatchedPixels: number = comparePng(
  img1, // First PNG: absolute file path or Buffer
  img2, // Second PNG: absolute file path or Buffer
  {
    excludedAreas,                // Regions to skip during comparison. Default: []
    diffFilePath,                 // Path to write the diff PNG (only written when mismatch > 0). Default: undefined
    throwErrorOnInvalidInputData, // Throw on missing/invalid input. Default: true
    pixelmatchOptions,            // Options forwarded to pixelmatch. Default: undefined
  }
);

expect(mismatchedPixels).toBe(0);

API Reference

comparePng(png1, png2, opts?): number

Compares two PNG images pixel-by-pixel and returns the number of mismatched pixels (0 means identical).

Parameters:

| Parameter | Type | Description | |-----------|------|-------------| | png1 | string \| Buffer | First PNG — absolute file path or raw PNG Buffer | | png2 | string \| Buffer | Second PNG — absolute file path or raw PNG Buffer | | opts | ComparePngOptions | Optional configuration object |


ComparePngOptions

| Option | Type | Default | Description | |--------|------|---------|-------------| | excludedAreas | Area[] | [] | Rectangular regions to exclude from comparison | | diffFilePath | string | undefined | File path for the diff PNG. Only written when result > 0 | | throwErrorOnInvalidInputData | boolean | true | Throw on missing/unsupported input. Set to false to treat invalid input as a zero-size PNG. An error is always thrown when both inputs are invalid | | pixelmatchOptions | PixelmatchOptions | undefined | Options forwarded to pixelmatch |


Area

type Area = {
  x1: number; // left edge (pixels from left)
  y1: number; // top edge (pixels from top)
  x2: number; // right edge (pixels from left, inclusive)
  y2: number; // bottom edge (pixels from top, inclusive)
};

PixelmatchOptions

| Option | Type | Default | Description | |--------|------|---------|-------------| | threshold | number | 0.1 | Matching threshold 01. Lower = more sensitive | | includeAA | boolean | false | When true, anti-aliased pixels count as mismatches | | alpha | number | 0.1 | Opacity of unchanged pixels in the diff image | | aaColor | [r, g, b] | [255, 255, 0] | Colour of anti-aliased pixels in the diff | | diffColor | [r, g, b] | [255, 0, 0] | Colour of differing pixels in the diff | | diffColorAlt | [r, g, b] | undefined | Alternative diff colour for dark pixels (dark-mode support) | | diffMask | boolean | false | Show only changed pixels on a transparent background |


License

MIT © dichovsky

Buy Me A Coffee

Support this project: Buy Me A Coffee