Skip to Content
New: codec-png-native and codec-png-wasm bring the blazediff-png codec to Node and WebAssembly, faster than spng and jSquash. Read more β†’
APIs@blazediff/core

@blazediff/core

High-performance pixel-by-pixel image comparison library. 1.5x faster than pixelmatchΒ  while maintaining identical accuracy.

View Detailed BenchmarksΒ 

Installation

npm install @blazediff/core

Features

  • 1.5x faster than pixelmatch on average, 88% faster on identical images
  • pixelmatch 8 adapter: @blazediff/core/pixelmatch is a drop-in replacement
  • Zero dependencies

API Reference

diff(a, b, options?)

Compares two RGBA images pixel by pixel. a and b are { data, width, height }, and browser ImageData fits as is. The same call, options and result exist in @blazediff/core-wasm and @blazediff/core-native.

import { diff } from "@blazediff/core"; const output = { data: new Uint8Array(width * height * 4), width, height }; const result = diff(a, b, { output }); if (result.kind === "compared" && !result.identical) { console.log(result.count, result.percentage); }
Options
OptionTypeDefaultDescription
thresholdnumber0.1Matching threshold (0-1). Lower is stricter
antialiasingbooleantrueDetect anti-aliased pixels and leave them out of the count
metric"yiq" | "oklab""yiq"Color metric. "oklab" is the metric of pixelmatch 8
maskUint8Array-One byte per pixel (width Γ— height). Non-zero pixels are skipped
windownumber-Also report the NΓ—N window with the most diff pixels
outputImage-Draw the diff here. Omit for a count-only comparison
render.alphanumber0.1Opacity of the original image in the output
render.diffColor[R,G,B][255,0,0]Color of different pixels
render.diffColorAlt[R,G,B]diffColorColor of pixels that get darker in b
render.aaColor[R,G,B][255,255,0]Color of anti-aliased pixels
render.background"faded" | "transparent""faded"transparent draws the diff without the gray copy of a
Result
KindFields
comparedcount, percentage, identical, and window: { x, y, count } when the window option is set
dimension-mismatcha and b, each { width, height }

Invalid buffers or options throw a BlazeDiffError with a code: invalid-image, invalid-output, invalid-mask or invalid-option.

pixelmatch(img1, img2, output, width, height, options?)

import pixelmatch from "@blazediff/core/pixelmatch" has the same signature, options, errors, counts and output bytes as pixelmatch 8.0.0, so you change the import and nothing else.

Threshold Guidelines: - 0.0 - Exact match only - 0.05 - Strict comparison - 0.1 - Default balanced comparison - 0.2 - Lenient comparison

Last updated on