-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffers.js
More file actions
40 lines (32 loc) · 1.22 KB
/
buffers.js
File metadata and controls
40 lines (32 loc) · 1.22 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
/**
* Example: Using Buffers instead of file paths
*/
import fs from 'node:fs';
import * as honeydiff from '../index.js';
async function main() {
console.log('Buffer Example\n');
// Load images as buffers
let img1Buffer = fs.readFileSync('../../tests/fixtures/screenshots/vizzly-baseline.png');
let img2Buffer = fs.readFileSync('../../tests/fixtures/screenshots/vizzly-with-diff.png');
console.log(`Loaded buffers: ${img1Buffer.length} and ${img2Buffer.length} bytes\n`);
// Compare using buffers
let result = await honeydiff.compare(img1Buffer, img2Buffer, {
pixelTolerance: 0,
includeSSIM: true,
});
console.log('Comparison result:');
console.log(` Different: ${result.isDifferent}`);
console.log(` Diff percentage: ${result.diffPercentage.toFixed(2)}%`);
console.log(` SSIM: ${result.perceptualScore?.toFixed(4) || 'N/A'}`);
// Mixed: buffer + file path
console.log('\nMixed comparison (buffer + file path):');
let mixedResult = await honeydiff.compare(
img1Buffer,
'../../tests/fixtures/screenshots/vizzly-with-diff.png'
);
console.log(` Diff percentage: ${mixedResult.diffPercentage.toFixed(2)}%`);
}
main().catch((err) => {
console.error('Error:', err);
process.exit(1);
});