Repository navigation
Expand file tree
/
Copy pathimage.js
More file actions
55 lines (46 loc) · 1.33 KB
/
Copy pathimage.js
File metadata and controls
55 lines (46 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
var q = require('q'),
gm = require('gm'),
inherit = require('inherit');
var gmCompare = q.denodeify(gm.compare.bind(gm));
module.exports = inherit({
__constructor: function(buffer) {
this._gm = gm(buffer);
},
crop: function crop(rect) {
this._gm.crop(rect.width, rect.height, rect.left, rect.top);
return q.resolve(this);
},
getSize: function() {
return q.ninvoke(this._gm, 'size');
},
save: function save(file) {
var d = q.defer();
this._gm.write(file, function(error) {
if (error) {
return d.reject(error);
}
d.fulfill(file);
});
return d.promise;
}
}, {
compare: function(path1, path2, tolerance) {
tolerance = tolerance || 0;
return gmCompare(path1, path2, tolerance).spread(function(equal) {
return equal;
});
},
buildDiff: function(opts) {
var gmOpts = {
file: opts.diff,
highlightStyle: 'assign'
};
if (opts.diffColor) {
//wrap color in quotes because gm does not escape it
//and # is treated as a comment
gmOpts.highlightColor = '"' + opts.diffColor + '"';
}
return gmCompare(opts.reference, opts.current, gmOpts);
}
});