-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageDiffTest.js
46 lines (34 loc) · 1.24 KB
/
imageDiffTest.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
import Rembrandt from 'rembrandt'
import fs from "fs"
let baseImage, secondImage, rembrandt
baseImage ='BaseImages/HaroldQApassed.png'
secondImage = 'BaseImages/HaroldQApassedincorrect.png',
rembrandt = new Rembrandt({
imageA: baseImage,
imageB: secondImage,
renderComposition: true,
compositionMaskColor: Rembrandt.Color.RED, // Color of unmatched pixels
maxOffset: 0,
maxThreshold: 0
});
let getResults = ((result)=>{
console.log('Result is:', result.passed)
console.log('Pixel Difference:', result.differences, `Percentage Difference: ${result.percentageDifference.toFixed(5)}%`)
});
let writeImageDiffToFile = ((result)=>{
getResults(result)
let buff = result.compositionImage
fs.writeFileSync(`diffImages/imageDiff${Date.now()}.png`, buff);
})
// Run the comparison
rembrandt.compare()
.then(function (result) {
result == 'true' ? getResults(result) : writeImageDiffToFile(result);
// console.log('Passed:', result.passed)
// console.log('Pixel Difference:', result.differences, 'Percentage Difference', result.percentageDifference, '%')
// let buff = result.compositionImage
// fs.writeFileSync(`diffImages/test${Date.now()}.png`, buff);
})
.catch((e) => {
console.error(e)
})