Comparing version 1.14.2 to 1.15.0
@@ -0,1 +1,11 @@ | ||
1.15.0 / 2014-05-03 | ||
=================== | ||
* changed; gm.compare logic to always run the mse comparison as expected #258 [Vokkim](https://github.com/Vokkim) | ||
* added; `tolerance` to gm.compare options object #258 [Vokkim](https://github.com/Vokkim) | ||
* added; option to set ImageMagick application path explicitly #250 (akreitals) | ||
* fixed; gm.compare: support values like 9.51582e-05 #260 [normanrz](https://github.com/normanrz) | ||
* README: add call for maintainers | ||
1.14.2 / 2013-12-24 | ||
@@ -2,0 +12,0 @@ =================== |
@@ -182,4 +182,5 @@ | ||
proto._spawn = function _spawn (args, bufferOutput, callback) { | ||
var appPath = this._options.appPath || ''; | ||
var bin = this._options.imageMagick | ||
? args.shift() | ||
? appPath + args.shift() | ||
: 'gm' | ||
@@ -186,0 +187,0 @@ |
@@ -17,3 +17,3 @@ // compare | ||
* @param {String} compareTo Path to another image to compare to `orig`. | ||
* @param {Number} [tolerance] Amount of difference to tolerate before failing - defaults to 0.4 | ||
* @param {Number|Object} [options] Options object or the amount of difference to tolerate before failing - defaults to 0.4 | ||
* @param {Function} cb(err, Boolean, equality, rawOutput) | ||
@@ -23,3 +23,3 @@ */ | ||
module.exports = exports = function (proto) { | ||
function compare(orig, compareTo, tolerance, cb) { | ||
function compare(orig, compareTo, options, cb) { | ||
orig = utils.escape(orig); | ||
@@ -31,38 +31,37 @@ compareTo = utils.escape(compareTo); | ||
var bin = isImageMagick ? '' : 'gm '; | ||
var execCmd = bin + 'compare -metric mse ' + orig + ' ' + compareTo; | ||
var tolerance = 0.4 | ||
// outputting the diff image | ||
if (typeof tolerance === 'object') { | ||
var diffOptions = tolerance; | ||
if (typeof diffOptions.file !== 'string') { | ||
throw new TypeError('The path for the diff output is invalid'); | ||
if (typeof options === 'object') { | ||
if (options.file) { | ||
if (typeof options.file !== 'string') { | ||
throw new TypeError('The path for the diff output is invalid'); | ||
} | ||
// graphicsmagick defaults to red | ||
var highlightColorOption = options.highlightColor | ||
? ' -highlight-color ' + options.highlightColor + ' ' | ||
: ' '; | ||
var diffFilename = utils.escape(options.file); | ||
// For IM, filename is the last argument. For GM it's `-file <filename>` | ||
var diffOpt = isImageMagick ? diffFilename : ('-file ' + diffFilename); | ||
execCmd += highlightColorOption + ' ' + diffOpt; | ||
} | ||
// graphicsmagick defaults to red | ||
var highlightColorOption = diffOptions.highlightColor | ||
? ' -highlight-color ' + diffOptions.highlightColor + ' ' | ||
: ' '; | ||
var diffFilename = utils.escape(diffOptions.file); | ||
// For IM, filename is the last argument. For GM it's `-file <filename>` | ||
var diffOpt = isImageMagick ? diffFilename : ('-file ' + diffFilename); | ||
var cmd = bin + 'compare' + highlightColorOption + orig + ' ' + compareTo + | ||
' ' + diffOpt; | ||
return exec(cmd, function (err, stdout, stderr) { | ||
// ImageMagick returns err code 2 if err, 0 if similar, 1 if dissimilar | ||
if (isImageMagick && err && err.code === 1) { | ||
err = null; | ||
if (options.tolerance) { | ||
if (typeof options.tolerance !== 'number') { | ||
throw new TypeError('The tolerance value should be a number'); | ||
} | ||
return cb(err, stdout, stderr); | ||
}); | ||
} | ||
tolerance = options.tolerance; | ||
} | ||
} else { | ||
// For ImageMagick diff file is required but we don't care about it, so null it out | ||
isImageMagick && (execCmd += ' null:'); | ||
// else, output the mean square error (mse) | ||
if ('function' == typeof tolerance) { | ||
cb = tolerance; | ||
tolerance = 0.4; | ||
if (typeof options == 'function') { | ||
cb = options; // tolerance value not provided, flip the cb place | ||
} else { | ||
tolerance = options | ||
} | ||
} | ||
var execCmd = bin + 'compare -metric mse ' + orig + ' ' + compareTo; | ||
// For ImageMagick diff file is required but we don't care about it, so null it out | ||
isImageMagick && (execCmd += ' null:'); | ||
exec(execCmd, function (err, stdout, stderr) { | ||
@@ -84,3 +83,3 @@ // ImageMagick returns err code 2 if err, 0 if similar, 1 if dissimilar | ||
// Otherwise, output format for IM is `12.00 (0.123)` and for GM it's `Total: 0.123` | ||
var regex = isImageMagick ? /\((\d+\.?\d*)\)/m : /Total: (\d+\.?\d*)/m; | ||
var regex = isImageMagick ? /\((\d+\.?[\d\-\+e]*)\)/m : /Total: (\d+\.?\d*)/m; | ||
var match = regex.exec(stdout); | ||
@@ -87,0 +86,0 @@ if (!match) { |
{ | ||
"name": "gm", | ||
"description": "GraphicsMagick and ImageMagick for node.js", | ||
"version": "1.14.2", | ||
"version": "1.15.0", | ||
"author": "Aaron Heckmann <aaron.heckmann+github@gmail.com>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -0,1 +1,4 @@ | ||
THIS REPOSITORY NEEDS A MAINTAINER. IF YOU'RE INTERESTED IN MAINTAING THIS MODULE, PLEASE LET US KNOW! | ||
# gm v1.14.2 [![Build Status](https://travis-ci.org/aheckmann/gm.png?branch=master)](https://travis-ci.org/aheckmann/gm) | ||
@@ -484,3 +487,3 @@ | ||
gm.compare(path1, path2 [, tolerance], callback) | ||
gm.compare(path1, path2 [, options], callback) | ||
@@ -511,2 +514,16 @@ ```js | ||
To output a diff image, pass a configuration object to define the diff options and tolerance. | ||
```js | ||
var options = { | ||
file: '/path/to/diff.png', | ||
highlightColor: 'yellow', | ||
tolerance: 0.02 | ||
} | ||
gm.compare('/path/to/image1.jpg', '/path/to/another.png', options, function (err, isEqual, equality, raw) { | ||
... | ||
}) | ||
``` | ||
## Contributors | ||
@@ -513,0 +530,0 @@ [https://github.com/aheckmann/gm/contributors](https://github.com/aheckmann/gm/contributors) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102693
1902
560