Repository navigation
Expand file tree
/
Copy pathimage.js
More file actions
70 lines (61 loc) · 1.75 KB
/
Copy pathimage.js
File metadata and controls
70 lines (61 loc) · 1.75 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
var q = require('q'),
looksSame = require('looks-same'),
PngImg = require('png-img'),
utils = require('png-img/utils'),
inherit = require('inherit');
module.exports = inherit({
__constructor: function(buffer) {
this._img = new PngImg(buffer);
},
crop: function crop(rect) {
this._img.crop(rect.left, rect.top, rect.width, rect.height);
return q.resolve(this);
},
getSize: function() {
return this._img.size();
},
getRGBA: function(x, y) {
return this._img.get(x, y);
},
save: function save(file) {
return q.ninvoke(this._img, 'save', file);
},
clear: function clear(area) {
this._img.fill(
area.left,
area.top,
area.width,
area.height,
'#000000'
);
}
}, {
compare: function(path1, path2, opts) {
opts = opts || {};
var compareOptions = {
strict: opts.strictComparison,
ignoreCaret: opts.canHaveCaret
};
if (!compareOptions.strict && 'tolerance' in opts) {
compareOptions.tolerance = opts.tolerance;
}
return q.nfcall(looksSame, path1, path2, compareOptions);
},
buildDiff: function(opts) {
var diffOptions = {
reference: opts.reference,
current: opts.current,
diff: opts.diff,
highlightColor: opts.diffColor,
strict: opts.strictComparison
};
if (!diffOptions.strict && 'tolerance' in opts) {
diffOptions.tolerance = opts.tolerance;
}
return q.nfcall(looksSame.createDiff, diffOptions);
},
RGBToString: function(rgb) {
return utils.RGBToString(rgb);
}
});