Skip to content

Commit

Permalink
'flags' object can be set as a property of compare's options paramete…
Browse files Browse the repository at this point in the history
…r. This can be used to provide any valid command-line option.
  • Loading branch information
cjcenizal committed Jun 6, 2016
1 parent c1bef9d commit 0761134
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,24 @@ gm.compare('/path/to/image1.jpg', '/path/to/another.png', options, function (err
})
```

You can also provide a `flags` property, which you can use to directly set
[command-line options](http://www.imagemagick.org/script/compare.php):

```js
var options = {
file: '/path/to/diff.png',
highlightColor: 'yellow',
tolerance: 0.02,
flags: {
'-compare': 'src',
'-colorspace': 'CMYK'
}
}
gm.compare('/path/to/image1.jpg', '/path/to/another.png', options, function (err, isEqual, equality, raw) {
...
})
```

##composite

GraphicsMagick supports compositing one image on top of another. This is exposed through `gm.composite()`. Its first argument is an image path with the changes to the base image, and an optional mask image.
Expand Down
20 changes: 17 additions & 3 deletions lib/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = exports = function (proto) {
var isImageMagick = this._options && this._options.imageMagick;
var appPath = this._options && this._options.appPath || '';
var bin = isImageMagick
? appPath + 'compare'
? appPath + 'compare'
: appPath + 'gm'
var args = ['-metric', 'mse', orig, compareTo]
if (!isImageMagick) {
Expand All @@ -37,6 +37,20 @@ module.exports = exports = function (proto) {
options.highlightColor = '"' + options.highlightColor + '"';
}

// Support all command line arguments.
if (typeof options.flags === 'object') {
for (var prop in options.flags) {
if (options.flags.hasOwnProperty(prop)) {
// Expect each command-line argument to be provided in the exact
// same format as they would be used in the CL, e.g. '-compose'
// and not 'compose'.
console.log(prop, options.flags[prop])
args.push(prop);
args.push(options.flags[prop]);
}
}
}

if (options.file) {
if (typeof options.file !== 'string') {
throw new TypeError('The path for the diff output is invalid');
Expand All @@ -56,13 +70,13 @@ module.exports = exports = function (proto) {
}
args.push(options.file);
}

if (typeof options.tolerance != 'undefined') {
if (typeof options.tolerance !== 'number') {
throw new TypeError('The tolerance value should be a number');
}
tolerance = options.tolerance;
}
}
} else {
// For ImageMagick diff file is required but we don't care about it, so null it out
if (isImageMagick) {
Expand Down

0 comments on commit 0761134

Please sign in to comment.