Merge pull request #437 from DanMMX/422

Adding hex colors wrapping
master
Rowan 9 years ago
commit 5a14305eeb
  1. 15
      examples/compare.js
  2. 5
      lib/compare.js
  3. 39
      test/422.js

@ -0,0 +1,15 @@
var gm = require('../')
, dir = __dirname + '/imgs'
, imgs = 'bitdepth.png original.jpg'.split(' ').map(function (img) {
return dir + '/' + img
})
, out = dir + '/compare.jpg'
gm.compare(imgs[0], imgs[1], { highlightColor: "#fff", file: out }, function (err) {
if (err) return console.dir(arguments)
console.log('The images are equal: %s', arguments[1]);
console.log('Actual equality: %d', arguments[2]);
console.log(this.outname + " created :: " + arguments[3]);
require('child_process').exec('open ' + out);
});

@ -30,6 +30,11 @@ module.exports = exports = function (proto) {
var tolerance = 0.4;
// outputting the diff image
if (typeof options === 'object') {
if (options.highlightColor && options.highlightColor.indexOf('"') < 0) {
options.highlightColor = '"' + options.highlightColor + '"';
}
if (options.file) {
if (typeof options.file !== 'string') {
throw new TypeError('The path for the diff output is invalid');

@ -0,0 +1,39 @@
var assert = require('assert');
var fs = require('fs');
module.exports = function (gm, dir, finish, GM) {
// Same image
GM.compare(dir + '/original.jpg', dir + '/original.png', function(err, same) {
if (err) return finish(err);
if (!same) return finish(new Error('Compare should be the same!'));
// Compare almost similar images for which ImageMagick
// returns a exponent-style floating point number
gm.compare(__dirname + '/fixtures/compare_1.png', __dirname + '/fixtures/compare_2.png', function(err, same, diff) {
if (err) return finish(err);
// Create a new noisy image
gm.noise(0.3).write(dir + '/noise3.png', function (err) {
if (err) return finish(err);
if (!same) return finish(new Error('Compare should be the same!'));
var options = {
highlightColor: '#fff',
highlightStyle: 'XOR',
file: dir + '/diff.png',
tolerance: 0.001
};
// Compare these images and write to a file.
GM.compare(dir + '/original.jpg', dir + '/noise3.png', options, function(err) {
if (err) return finish(err);
fs.exists(options.file, function(exists) {
if (exists) finish();
else finish(new Error('Diff file does not exist.'));
});
});
});
});
});
};
Loading…
Cancel
Save