JavaScript像素级图像比较库:pixelmatch

fkd27 9年前

最小,最简单,和最快的JavaScript 像素级图像比较库,主要设计用于回归测试的对比截图。

API

pixelmatch(img1, img2, output, width, height[, threshold, antialiasing])

  • img1,img2— Image data of the images to compare (BufferorUint8Array).
  • output— Image data to write the diff to.
  • width,height— Width and height of the images. Note that all three images need to have the same dimensions.
  • threshold— Matching threshold, ranges from0to1. Smaller values make the comparison more sensitive.0.005by default.
  • antialiasing— Radius of antialiasing to ignore in pixels.1by default.

Compares two images, writes the output diff and returns the number of mismatched pixels.

Command line

Pixelmatch comes with a binary that works with PNG images:

pixelmatch image1.png image2.png output.png 0.005 1

Install

Install with NPM:

npm install pixelmatch

To build a browser-compatible version, clone the repository locally, then run:

npm install -g browserify  browserify -s pixelmatch index.js > pixelmatch.js



项目主页:http://www.open-open.com/lib/view/home/1445081018435