pixelmatch 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var PNG = require('pngjs').PNG,
  4. fs = require('fs'),
  5. match = require('../.');
  6. if (process.argv.length < 5) {
  7. console.log('Usage: imagematch image1.png image2.png output.png [threshold=0.005] [includeAA=false]');
  8. return;
  9. }
  10. var threshold = isNaN(+process.argv[5]) ? undefined : +process.argv[5],
  11. includeAA = process.argv[6] === 'true';
  12. var img1 = fs.createReadStream(process.argv[2]).pipe(new PNG()).on('parsed', doneReading);
  13. var img2 = fs.createReadStream(process.argv[3]).pipe(new PNG()).on('parsed', doneReading);
  14. function doneReading() {
  15. if (!img1.data || !img2.data) return;
  16. var diff = new PNG({width: img1.width, height: img1.height});
  17. console.time('match');
  18. var diffs = match(img1.data, img2.data, diff.data, diff.width, diff.height, {
  19. threshold: threshold,
  20. includeAA: includeAA
  21. });
  22. console.timeEnd('match');
  23. diff.pack().pipe(fs.createWriteStream(process.argv[4]));
  24. console.log('different pixels: ' + diffs);
  25. console.log('error: ' + (Math.round(100 * 100 * diffs / (diff.width * diff.height)) / 100) + '%');
  26. }