Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gm

Package Overview
Dependencies
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gm - npm Package Compare versions

Comparing version 1.13.3 to 1.14.0

13

History.md

@@ -0,3 +1,9 @@

1.14.0 / 2013-12-04
===================
* added; compare method for imagemagick (longlho)
1.13.3 / 2013-10-22
===================
* fixed; escape diffOptions.file in compare (dwabyick)

@@ -7,2 +13,3 @@

===================
* fixed; density is a setting not an operator

@@ -12,2 +19,3 @@

===================
* added; boolean for % crop

@@ -17,2 +25,3 @@

===================
* added; morph more than two images (overra)

@@ -22,2 +31,3 @@

===================
* fixed; fallback to through in node 0.8

@@ -27,2 +37,3 @@

===================
* refactor; replace through with stream.PassThrough

@@ -32,2 +43,3 @@

===================
* added; diff image output file (chenglou)

@@ -37,2 +49,3 @@

===================
* added; proto.selectFrame(#)

@@ -39,0 +52,0 @@ * fixed; getters should not ignore frame selection

3

index.js

@@ -118,2 +118,3 @@

require("./lib/command")(gm.prototype);
require("./lib/compare")(gm.prototype);

@@ -126,3 +127,3 @@ /**

module.exports.utils = require('./lib/utils');
module.exports.compare = require('./lib/compare');
module.exports.compare = require('./lib/compare')();
module.exports.version = JSON.parse(

@@ -129,0 +130,0 @@ require('fs').readFileSync(__dirname + '/package.json', 'utf8')

@@ -21,39 +21,79 @@ // compare

module.exports = exports = function compare (orig, compareTo, tolerance, cb) {
orig = utils.escape(orig);
compareTo = utils.escape(compareTo);
module.exports = exports = function (proto) {
function compare(orig, compareTo, tolerance, cb) {
orig = utils.escape(orig);
compareTo = utils.escape(compareTo);
// 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');
var isImageMagick = this._options && this._options.imageMagick;
// compare binary for IM is `compare`, for GM it's `gm compare`
var bin = isImageMagick ? '' : 'gm ';
// 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');
}
// 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;
}
return cb(err, stdout, stderr);
});
}
// graphicsmagick defaults to red
var highlightColorOption = diffOptions.highlightColor
? ' -highlight-color ' + diffOptions.highlightColor + ' '
: ' ';
return exec('gm compare' + highlightColorOption + orig + ' ' + compareTo +
' -file ' + utils.escape(diffOptions.file), cb);
// else, output the mean square error (mse)
if ('function' == typeof tolerance) {
cb = tolerance;
tolerance = 0.4;
}
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) {
// ImageMagick returns err code 2 if err, 0 if similar, 1 if dissimilar
if (isImageMagick) {
if (!err) {
return cb(null, 0 <= tolerance, 0, stdout);
}
if (err.code === 1) {
err = null;
stdout = stderr;
}
}
if (err) {
return cb(err);
}
// Since ImageMagick similar gives err code 0 and no stdout, there's really no matching
// 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 match = regex.exec(stdout);
if (!match) {
err = new Error('Unable to parse output.\nGot ' + stdout);
return cb(err);
}
var equality = parseFloat(match[1]);
cb(null, equality <= tolerance, equality, stdout);
});
}
// else, output the mean square error (mse)
if ('function' == typeof tolerance) {
cb = tolerance;
tolerance = 0.4;
if (proto) {
proto.compare = compare;
}
return compare;
};
exec('gm compare -metric mse ' + orig + ' ' + compareTo, function (err, stdout, stderr) {
if (err) return cb(err);
var match = /Total: (\d+\.?\d*)/m.exec(stdout);
if (!match) {
err = new Error('Unable to parse output.\nGot ' + stdout);
return cb(err);
}
var equality = parseFloat(match[1]);
cb(null, equality <= tolerance, equality, stdout);
});
}
{
"name": "gm",
"description": "GraphicsMagick and ImageMagick for node.js",
"version": "1.13.3",
"version": "1.14.0",
"author": "Aaron Heckmann <aaron.heckmann+github@gmail.com>",

@@ -6,0 +6,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc