mirror of https://gitgud.io/fatchan/gm
commit
5a14305eeb
3 changed files with 59 additions and 0 deletions
@ -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); |
||||
}); |
||||
|
@ -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…
Reference in new issue