@blazediff/cli 1.8.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -23
- package/dist/cli.js +9406 -140
- package/dist/commands/bin.js +145 -0
- package/dist/commands/core.js +8984 -0
- package/dist/commands/gmsd.js +8727 -17
- package/dist/commands/hitchhikers-ssim.js +8704 -17
- package/dist/commands/msssim.js +8739 -15
- package/dist/commands/ssim.js +8770 -15
- package/package.json +3 -2
- package/dist/commands/diff.js +0 -255
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/commands/bin.ts
|
|
22
|
+
var bin_exports = {};
|
|
23
|
+
__export(bin_exports, {
|
|
24
|
+
default: () => main
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(bin_exports);
|
|
27
|
+
var import_bin = require("@blazediff/bin");
|
|
28
|
+
function printUsage() {
|
|
29
|
+
console.log(`
|
|
30
|
+
Usage: blazediff-cli bin <image1> <image2> <output> [options]
|
|
31
|
+
|
|
32
|
+
Arguments:
|
|
33
|
+
image1 Path to the first image
|
|
34
|
+
image2 Path to the second image
|
|
35
|
+
output Path for the diff image output
|
|
36
|
+
|
|
37
|
+
Options:
|
|
38
|
+
-t, --threshold <num> Color difference threshold (0 to 1, default: 0.1)
|
|
39
|
+
-a, --antialiasing Enable anti-aliasing detection
|
|
40
|
+
--diff-mask Output only differences (transparent background)
|
|
41
|
+
--fail-on-layout Fail immediately if images have different dimensions
|
|
42
|
+
-c, --compression <num> PNG compression level (0-9, default: 0)
|
|
43
|
+
-h, --help Show this help message
|
|
44
|
+
|
|
45
|
+
Examples:
|
|
46
|
+
blazediff-cli bin image1.png image2.png diff.png
|
|
47
|
+
blazediff-cli bin image1.png image2.png diff.png -t 0.05 -a
|
|
48
|
+
blazediff-cli bin image1.png image2.png diff.png --threshold 0.2 --antialiasing
|
|
49
|
+
`);
|
|
50
|
+
}
|
|
51
|
+
async function main() {
|
|
52
|
+
try {
|
|
53
|
+
const args = process.argv.slice(2);
|
|
54
|
+
if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
|
|
55
|
+
printUsage();
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
if (args.length < 3) {
|
|
59
|
+
console.error("Error: Two image paths and an output path are required");
|
|
60
|
+
printUsage();
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
const image1 = args[0];
|
|
64
|
+
const image2 = args[1];
|
|
65
|
+
const output = args[2];
|
|
66
|
+
const options = {};
|
|
67
|
+
for (let i = 3; i < args.length; i++) {
|
|
68
|
+
const arg = args[i];
|
|
69
|
+
const nextArg = args[i + 1];
|
|
70
|
+
switch (arg) {
|
|
71
|
+
case "-t":
|
|
72
|
+
case "--threshold":
|
|
73
|
+
if (nextArg) {
|
|
74
|
+
const threshold = parseFloat(nextArg);
|
|
75
|
+
if (Number.isNaN(threshold) || threshold < 0 || threshold > 1) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Invalid threshold: ${nextArg}. Must be between 0 and 1`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
options.threshold = threshold;
|
|
81
|
+
i++;
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
case "-a":
|
|
85
|
+
case "--antialiasing":
|
|
86
|
+
options.antialiasing = true;
|
|
87
|
+
break;
|
|
88
|
+
case "--diff-mask":
|
|
89
|
+
options.diffMask = true;
|
|
90
|
+
break;
|
|
91
|
+
case "--fail-on-layout":
|
|
92
|
+
options.failOnLayoutDiff = true;
|
|
93
|
+
break;
|
|
94
|
+
case "-c":
|
|
95
|
+
case "--compression":
|
|
96
|
+
if (nextArg) {
|
|
97
|
+
const compression = parseInt(nextArg, 10);
|
|
98
|
+
if (Number.isNaN(compression) || compression < 0 || compression > 9) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`Invalid compression: ${nextArg}. Must be between 0 and 9`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
options.compression = compression;
|
|
104
|
+
i++;
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
console.error(`Unknown option: ${arg}`);
|
|
109
|
+
printUsage();
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const startTime = performance.now();
|
|
114
|
+
const result = await (0, import_bin.compare)(image1, image2, output, options);
|
|
115
|
+
const duration = performance.now() - startTime;
|
|
116
|
+
console.log(`completed in: ${duration.toFixed(2)}ms`);
|
|
117
|
+
if (result.match) {
|
|
118
|
+
console.log("Images are identical!");
|
|
119
|
+
process.exit(0);
|
|
120
|
+
}
|
|
121
|
+
if (result.reason === "layout-diff") {
|
|
122
|
+
console.log("Images have different dimensions");
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
if (result.reason === "file-not-exists") {
|
|
126
|
+
console.error(`File not found: ${result.file}`);
|
|
127
|
+
process.exit(2);
|
|
128
|
+
}
|
|
129
|
+
if (result.reason === "pixel-diff") {
|
|
130
|
+
console.log(`different pixels: ${result.diffCount}`);
|
|
131
|
+
console.log(`error: ${result.diffPercentage.toFixed(2)}%`);
|
|
132
|
+
console.log(`diff image: ${output}`);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error(
|
|
137
|
+
"Error:",
|
|
138
|
+
error instanceof Error ? error.message : String(error)
|
|
139
|
+
);
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (typeof require !== "undefined" && require.main === module) {
|
|
144
|
+
main();
|
|
145
|
+
}
|