
Security News
Deno Goes the Way of the Dinosaur
Cloudflare is acquiring Deno’s team, which will provide another year of bug fixes and security updates before ending support for the runtime.
pixelmatch
Advanced tools
The smallest, simplest and fastest JavaScript pixel-level image comparison library, originally created to compare screenshots in tests.
Features accurate anti-aliased pixels detection and perceptual color difference metrics.
Inspired by Resemble.js and Blink-diff. Unlike these libraries, pixelmatch is around 150 lines of code, has no dependencies, and works on raw typed arrays of image data, so it's blazing fast and can be used in any environment (Node or browsers).
const numDiffPixels = pixelmatch(img1, img2, diff, 800, 600, {threshold: 0.1});
Implements ideas from the following papers:
| expected | actual | diff |
|---|---|---|
img1, img2 — Image data of the images to compare (Buffer, Uint8Array or Uint8ClampedArray). Note: image dimensions must be equal.output — Image data to write the diff to, or null if don't need a diff image.width, height — Width and height of the images. Note that all three images need to have the same dimensions.options is an object literal with the following properties:
threshold — Matching threshold, ranges from 0 to 1. Smaller values make the comparison more sensitive. 0.1 by default.includeAA — If true, disables detecting and ignoring anti-aliased pixels. false by default.alpha — Blending factor of unchanged pixels in the diff output. Ranges from 0 for pure white to 1 for original brightness. 0.1 by default.aaColor — The color of anti-aliased pixels in the diff output in [R, G, B] format. [255, 255, 0] by default.diffColor — The color of differing pixels in the diff output in [R, G, B] format. [255, 0, 0] by default.diffColorAlt — An alternative color to use for dark on light differences to differentiate between "added" and "removed" parts. If not provided, all differing pixels use the color specified by diffColor. null by default.diffMask — Draw the diff over a transparent background (a mask), rather than over the original image. Will not draw anti-aliased pixels (if detected).Compares two images, writes the output diff and returns the number of mismatched pixels.
Pixelmatch comes with a binary that works with PNG images:
pixelmatch image1.png image2.png output.png 0.1
import fs from 'fs';
import {PNG} from 'pngjs';
import pixelmatch from 'pixelmatch';
const img1 = PNG.sync.read(fs.readFileSync('img1.png'));
const img2 = PNG.sync.read(fs.readFileSync('img2.png'));
const {width, height} = img1;
const diff = new PNG({width, height});
pixelmatch(img1.data, img2.data, diff.data, width, height, {threshold: 0.1});
fs.writeFileSync('diff.png', PNG.sync.write(diff));
const img1 = img1Context.getImageData(0, 0, width, height);
const img2 = img2Context.getImageData(0, 0, width, height);
const diff = diffContext.createImageData(width, height);
pixelmatch(img1.data, img2.data, diff.data, width, height, {threshold: 0.1});
diffContext.putImageData(diff, 0, 0);
Install with NPM:
npm install pixelmatch
Or use in the browser from a CDN:
<script type="module">
import pixelmatch from 'https://esm.run/pixelmatch';
Resemble.js is a package similar to pixelmatch that analyzes and compares images with a focus on visual differences. It provides more detailed analysis options, such as the ability to ignore colors or to get a percentage of image similarity. However, it might be heavier in terms of dependencies compared to the lightweight nature of pixelmatch.
Looks-same is another npm package that offers image comparison capabilities. It focuses on flexibility, offering features like tolerance to color and antialiasing differences. Compared to pixelmatch, looks-same provides a higher-level API that might be more accessible to some users, but potentially at the cost of lower-level control and performance.
FAQs
The smallest and fastest pixel-level image comparison library.
The npm package pixelmatch receives a total of 5,200,404 weekly downloads. As such, pixelmatch popularity was classified as popular.
We found that pixelmatch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 29 open source maintainers collaborating on the project.

Security News
Cloudflare is acquiring Deno’s team, which will provide another year of bug fixes and security updates before ending support for the runtime.

Security News
Anthropic’s free OSS Scanner uses Mythos and other Claude models to find open source vulnerabilities and send maintainers reports with proposed fixes.

Security News
On Front Lines’ Early Adopters: CISO podcast, Andrew Becherer shares lessons from Datadog, weighs the long-term costs of AI-built tools, and explains how founders can actually gain a CISO’s trust.