forked from stoarca/phantesta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagediffer.js
53 lines (52 loc) · 1.34 KB
/
imagediffer.js
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
var ImageDiffer = function() {
this.waiting = false;
this.result = null;
// TODO: kinda in the wrong place
resemble.outputSettings({
transparency: 0.5,
largeImageThreshold: 0,
useCrossOrigin: false,
});
this.skipBoxes = [];
this.includeBoxes = [];
};
ImageDiffer.prototype.censorBoxes = function(boxes) {
this.skipBoxes = boxes || [];
return this;
};
ImageDiffer.prototype.includeOnlyBoxes = function(boxes) {
this.includeBoxes = boxes || [];
return this;
};
ImageDiffer.prototype.doDiff = function() {
var self = this;
this.waiting = true;
this.result = null;
var a = document.getElementById('a').files[0];
var b = document.getElementById('b').files[0];
return resemble(a)
.compareTo(b)
.ignoreNothing()
.skip(this.skipBoxes)
.include(this.includeBoxes)
.onComplete(function(result) {
self.waiting = false;
self.result = result;
var image = new Image();
document.getElementById('result').appendChild(image);
image.src = result.getImageDataUrl();
});
}
ImageDiffer.prototype.isReady = function() {
return !this.waiting;
};
ImageDiffer.prototype.getResult = function() {
if (!this.result && this.waiting) {
throw new Error('result is not ready yet!');
}
return this.result;
};
var go = function() {
var imageDiffer = new ImageDiffer();
imageDiffer.doDiff();
};