Skip to Content
New: blazediff-png - a from-scratch Rust PNG codec, byte-exact to libspng and faster on every fixture. Read more β†’
DocsPixel-by-pixel Image ComparisonπŸ†πŸ†πŸ† Rust + N-API in Node

Pixel-by-pixel Comparison - Rust + N-API in Node

The fastest path: native Rust compiled to a Node addon via N-API, ~3-4Γ— faster than odiff. @blazediff/core-native accepts file paths or encoded Buffer and Uint8Array inputs. It decodes PNG, JPEG, and QOI itself in parallel and can write the diff image straight to disk. Reach for it in Node test runners and CI when you want maximum throughput.

Installation

npm install @blazediff/core-native

Examples

Fixture A

Image 1

Fixture B

Image 2

Result

import { compare } from "@blazediff/core-native"; const result = await compare("3a.png", "3b.png"); if (result.match) { console.log("identical"); } else if (result.reason === "pixel-diff") { console.log(`${result.diffCount} pixels differ (${result.diffPercentage.toFixed(2)}%)`); } else if (result.reason === "layout-diff") { console.log("dimensions differ"); }

Encoded inputs are borrowed directly for each synchronous native call, so the JavaScript bytes are not copied into Rust. PNG, JPEG, or QOI decoding still allocates native RGBA pixel buffers.

Want a verdict on what changed, not just how many pixels? Pass interpret: true or use the dedicated Image Difference Analysis β†’ example. Full options in the API reference β†’.

Last updated on