Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Return non-zero exit code when given images differ #54

Merged
merged 6 commits into from
Feb 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions bin/pixelmatch
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env node
/* eslint-disable no-process-exit */

'use strict';

var PNG = require('pngjs').PNG,
Expand All @@ -7,7 +9,7 @@ var PNG = require('pngjs').PNG,

if (process.argv.length < 5) {
console.log('Usage: pixelmatch image1.png image2.png output.png [threshold=0.005] [includeAA=false]');
return;
process.exit(64);
}

var threshold = isNaN(+process.argv[5]) ? undefined : +process.argv[5],
Expand All @@ -22,7 +24,7 @@ function doneReading() {
if (img1.width !== img2.width || img1.height !== img2.height) {
console.log('Image dimensions do not match: %dx%d vs %dx%d',
img1.width, img1.height, img2.width, img2.height);
return;
process.exit(65);
}

var diff = new PNG({width: img1.width, height: img1.height});
Expand All @@ -34,8 +36,12 @@ function doneReading() {
});
console.timeEnd('match');

diff.pack().pipe(fs.createWriteStream(process.argv[4]));
var writeStream = diff.pack().pipe(fs.createWriteStream(process.argv[4]));

console.log('different pixels: ' + diffs);
console.log('error: ' + (Math.round(100 * 100 * diffs / (diff.width * diff.height)) / 100) + '%');

writeStream.on('close', function () {
process.exit(diffs ? 66 : 0);
});
}