Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'flags' object can be set as a property of compare's options parameter. #535

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
additional [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