@argos-ci/mask-fingerprint

中文文档
0.1.3发布于 2026/01/19MITTypeScriptCommonJS零依赖构建来源已验证近 30 天下载 5433

Fast, deterministic visual diff fingerprinting for PNG images, exposed as a Node.js native module via N-API.

原始使用文档
文档目录13 节
  1. What problem this solves
  2. How it works
  3. Installation
  4. Requirements
  5. Install dependencies
  6. Usage
  7. API
  8. fingerprintDiff(buffer, options?)
  9. Supported PNG formats
  10. Performance characteristics
  11. When to use this
  12. Development
  13. License

mask-fingerprint

Fast, deterministic visual diff fingerprinting for PNG images, exposed as a Node.js native module via N-API.

This library takes a PNG diff image (for example red-pixel visual diffs) and produces a stable equality fingerprint.
Two diffs that are visually very close will produce the same fingerprint, enabling:

  • fingerprintA === fingerprintB
  • database indexing
  • grouping and deduplication
  • joins without custom comparison logic

The core algorithm is written in Rust for performance and exposed to Node.js.

What problem this solves

Classic perceptual hashes require distance comparisons, which do not work well with SQL indexes or strict equality.

This project instead:

  • normalizes the diff mask
  • quantizes spatial density
  • hashes a coarse representation

The result is tolerant equality, not approximate similarity.

How it works

  1. Decode PNG into RGBA
  2. Extract a binary mask of red pixels
  3. Optional dilation to absorb small pixel noise
  4. Crop to the bounding box
  5. Optional square padding
  6. Split into a small grid (8×8, 16×16, or 32×32)
  7. Compute per-cell red density
  8. Quantize densities into bins
  9. Pack bits and hash with FNV-1a 64-bit
  10. Return a deterministic string key

Small local differences usually do not change the final fingerprint.

Installation

Requirements

  • Node.js 24 or newer
  • Rust stable
  • Cargo

Install dependencies

pnpm install

or

npm install

This builds the native module.

Usage

import fs from 'node:fs'
import { fingerprintDiff } from 'mask-fingerprint'

const png = fs.readFileSync('diff.png')

const fingerprint = await fingerprintDiff(png, {
  gridSize: 16,
  dilateRadius: 1,
  padToSquare: true,
  densityThresholds: [0.002, 0.02, 0.08],
  redThreshold: {
    rMin: 200,
    gMax: 90,
    bMax: 90,
    aMin: 16,
  },
})

console.log(fingerprint)
// v1:g16:d1:t0.002,0.02,0.08:3fa1c2e9a4b8d210

The returned value is designed to be stored in a database, indexed, and compared using strict equality.

API

fingerprintDiff(buffer, options?)

Returns a Promise<string>.

Parameters

buffer

  • Node.js Buffer
  • Raw PNG file contents

options (optional)

{
  gridSize?: 8 | 16 | 32        // default: 16
  dilateRadius?: 0 | 1          // default: 1
  padToSquare?: boolean         // default: true

  densityThresholds?: number[]  // default: [0.002, 0.02, 0.08]
                                // sorted, values between 0 and 1

  redThreshold?: {
    rMin?: number               // default: 200
    gMax?: number               // default: 90
    bMax?: number               // default: 90
    aMin?: number               // default: 16
  }
}

Returns

string

A deterministic fingerprint string suitable for equality comparison and indexing.

Supported PNG formats

  • RGBA
  • RGB
  • Grayscale
  • Grayscale with alpha
  • Indexed or palette PNGs

Palette and low bit-depth images are automatically expanded.

Performance characteristics

  • Linear time in number of pixels
  • No heavy floating-point operations
  • Minimal allocations in hot paths
  • Suitable for batch processing

Typical workloads handle thousands of diffs per second.

When to use this

Good fit:

  • Visual regression testing
  • Screenshot diff deduplication
  • CI artifact clustering
  • Database-backed visual change tracking

Not a good fit:

  • General image similarity search
  • Large geometric transformations
  • Rotation or strong scale invariance

This library is intentionally optimized for diff masks, not arbitrary images.

Development

cargo check
cargo test

Rebuild the native module:

pnpm build

License

MIT

版本与发布记录

@argos-ci/mask-fingerprint 共发布 6 个版本,首次发布于 2026/01/12;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.3latest2026/01/199 个月前
0.1.22026/01/149 个月前
0.1.12026/01/139 个月前
0.1.02026/01/139 个月前
0.0.22026/01/139 个月前
0.0.12026/01/129 个月前

关于 @argos-ci/mask-fingerprint 的常见问题

@argos-ci/mask-fingerprint 是什么?

Fast, deterministic visual diff fingerprinting for PNG images, exposed as a Node.js native module via N-API.

如何安装 @argos-ci/mask-fingerprint?

在项目目录运行 npm install @argos-ci/mask-fingerprint,或使用 pnpm add / yarn add / bun add。

@argos-ci/mask-fingerprint 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@argos-ci/mask-fingerprint 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@argos-ci/mask-fingerprint 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@argos-ci/mask-fingerprint 可以商用吗?

@argos-ci/mask-fingerprint 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@argos-ci/mask-fingerprint 的下载量有多少?

根据 npm 官方下载统计,@argos-ci/mask-fingerprint 在 2026/10/07 – 2026/11/05 这 30 天内被下载 5,433 次,日均约 181 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@argos-ci/mask-fingerprint 还在维护吗?

最新版本 0.1.3 发布于 2026/01/19(9 个月前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/01/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。