Skip to content

Commit

Permalink
Merge pull request #437 from DanMMX/422
Browse files Browse the repository at this point in the history
Adding hex colors wrapping
  • Loading branch information
rwky committed Aug 26, 2015
2 parents b626df2 + 7fe8e0f commit 5a14305
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/compare.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);
});

5 changes: 5 additions & 0 deletions lib/compare.js
Expand Up @@ -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');
Expand Down
39 changes: 39 additions & 0 deletions test/422.js
@@ -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.'));
});
});
});
});
});
};

0 comments on commit 5a14305

Please sign in to comment.