@blazediff/bin 0.0.1

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Teimur Gasanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/cli.js ADDED
@@ -0,0 +1,247 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/index.ts
27
+ var import_core = __toESM(require("@blazediff/core"));
28
+ async function compareImages(image1Path, image2Path, options) {
29
+ const [image1, image2] = await Promise.all([
30
+ options.transformer.transform(image1Path),
31
+ options.transformer.transform(image2Path)
32
+ ]);
33
+ if (image1.width !== image2.width || image1.height !== image2.height) {
34
+ throw new Error(
35
+ `Image dimensions do not match: ${image1.width}x${image1.height} vs ${image2.width}x${image2.height}`
36
+ );
37
+ }
38
+ let outputData;
39
+ if (options.outputPath) {
40
+ outputData = new Uint8Array(image1.data.length);
41
+ }
42
+ const startTime = performance.now();
43
+ const diffCount = (0, import_core.default)(
44
+ image1.data,
45
+ image2.data,
46
+ outputData,
47
+ image1.width,
48
+ image1.height,
49
+ options.coreOptions
50
+ );
51
+ const duration = performance.now() - startTime;
52
+ return {
53
+ diffCount,
54
+ width: image1.width,
55
+ height: image1.height,
56
+ outputData,
57
+ duration
58
+ };
59
+ }
60
+
61
+ // src/cli.ts
62
+ function printUsage() {
63
+ console.log(`
64
+ Usage: blazediff <image1> <image2> [options]
65
+
66
+ Arguments:
67
+ image1 Path to the first image
68
+ image2 Path to the second image
69
+
70
+ Options:
71
+ -o, --output <path> Output path for the diff image
72
+ -t, --threshold <num> Matching threshold (0 to 1, default: 0.1)
73
+ -a, --alpha <num> Opacity of original image in diff (default: 0.1)
74
+ --aa-color <r,g,b> Color for anti-aliased pixels (default: 255,255,0)
75
+ --diff-color <r,g,b> Color for different pixels (default: 255,0,0)
76
+ --diff-color-alt <r,g,b> Alternative color for dark differences (default: same as diff-color)
77
+ --include-aa Include anti-aliasing detection
78
+ --diff-mask Draw diff over transparent background
79
+ --transformer <name> Specify transformer to use (e.g. pngjs, sharp)
80
+ -h, --help Show this help message
81
+
82
+ Examples:
83
+ blazediff image1.png image2.png
84
+ blazediff image1.png image2.png -o diff.png -t 0.05
85
+ blazediff image1.png image2.png --threshold 0.2 --alpha 0.3
86
+ `);
87
+ }
88
+ function parseRGB(colorStr) {
89
+ const parts = colorStr.split(",").map((s) => parseInt(s.trim()));
90
+ if (parts.length !== 3 || parts.some((p) => isNaN(p) || p < 0 || p > 255)) {
91
+ throw new Error(
92
+ `Invalid RGB color format: ${colorStr}. Expected format: r,g,b (e.g., 255,0,0)`
93
+ );
94
+ }
95
+ return [parts[0], parts[1], parts[2]];
96
+ }
97
+ function parseArgs() {
98
+ const args = process.argv.slice(2);
99
+ if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
100
+ printUsage();
101
+ process.exit(0);
102
+ }
103
+ if (args.length < 2) {
104
+ console.error("Error: Two image paths are required");
105
+ printUsage();
106
+ process.exit(1);
107
+ }
108
+ const image1 = args[0];
109
+ const image2 = args[1];
110
+ const options = {};
111
+ for (let i = 2; i < args.length; i++) {
112
+ const arg = args[i];
113
+ const nextArg = args[i + 1];
114
+ switch (arg) {
115
+ case "-o":
116
+ case "--output":
117
+ if (nextArg) {
118
+ options.outputPath = nextArg;
119
+ i++;
120
+ }
121
+ break;
122
+ case "-t":
123
+ case "--threshold":
124
+ if (nextArg) {
125
+ const threshold = parseFloat(nextArg);
126
+ if (isNaN(threshold) || threshold < 0 || threshold > 1) {
127
+ throw new Error(
128
+ `Invalid threshold: ${nextArg}. Must be between 0 and 1`
129
+ );
130
+ }
131
+ options.threshold = threshold;
132
+ i++;
133
+ }
134
+ break;
135
+ case "-a":
136
+ case "--alpha":
137
+ if (nextArg) {
138
+ const alpha = parseFloat(nextArg);
139
+ if (isNaN(alpha) || alpha < 0 || alpha > 1) {
140
+ throw new Error(
141
+ `Invalid alpha: ${nextArg}. Must be between 0 and 1`
142
+ );
143
+ }
144
+ options.alpha = alpha;
145
+ i++;
146
+ }
147
+ break;
148
+ case "--aa-color":
149
+ if (nextArg) {
150
+ options.aaColor = parseRGB(nextArg);
151
+ i++;
152
+ }
153
+ break;
154
+ case "--diff-color":
155
+ if (nextArg) {
156
+ options.diffColor = parseRGB(nextArg);
157
+ i++;
158
+ }
159
+ break;
160
+ case "--diff-color-alt":
161
+ if (nextArg) {
162
+ options.diffColorAlt = parseRGB(nextArg);
163
+ i++;
164
+ }
165
+ break;
166
+ case "--include-aa":
167
+ options.includeAA = true;
168
+ break;
169
+ case "--diff-mask":
170
+ options.diffMask = true;
171
+ break;
172
+ case "--transformer":
173
+ if (nextArg) {
174
+ options.transformer = nextArg;
175
+ i++;
176
+ }
177
+ break;
178
+ default:
179
+ console.error(`Unknown option: ${arg}`);
180
+ printUsage();
181
+ process.exit(1);
182
+ }
183
+ }
184
+ return { image1, image2, options };
185
+ }
186
+ var getTransformer = async (transformer) => {
187
+ if (!transformer || transformer === "pngjs") {
188
+ const { default: transformer2 } = await import("@blazediff/pngjs-transformer");
189
+ return transformer2;
190
+ }
191
+ if (transformer === "sharp") {
192
+ const { default: transformer2 } = await import("@blazediff/sharp-transformer");
193
+ return transformer2;
194
+ }
195
+ throw new Error(`Unknown transformer: ${transformer}`);
196
+ };
197
+ async function main() {
198
+ try {
199
+ const { image1, image2, options } = parseArgs();
200
+ const transformer = await getTransformer(options.transformer);
201
+ const result = await compareImages(image1, image2, {
202
+ outputPath: options.outputPath,
203
+ transformer,
204
+ coreOptions: {
205
+ threshold: options.threshold,
206
+ alpha: options.alpha,
207
+ aaColor: options.aaColor,
208
+ diffColor: options.diffColor,
209
+ diffColorAlt: options.diffColorAlt,
210
+ includeAA: options.includeAA,
211
+ diffMask: options.diffMask
212
+ }
213
+ });
214
+ console.log(`matched in: ${result.duration.toFixed(2)}ms`);
215
+ console.log(`dimensions: ${result.width}x${result.height}`);
216
+ console.log(`different pixels: ${result.diffCount}`);
217
+ console.log(
218
+ `error: ${(result.diffCount / (result.width * result.height) * 100).toFixed(2)}%`
219
+ );
220
+ if (options.outputPath && result.outputData) {
221
+ await transformer.write(
222
+ {
223
+ data: result.outputData,
224
+ width: result.width,
225
+ height: result.height
226
+ },
227
+ options.outputPath
228
+ );
229
+ console.log(`diff image: ${options.outputPath}`);
230
+ }
231
+ if (result.diffCount > 0) {
232
+ process.exit(1);
233
+ } else {
234
+ console.log(`Images are identical!`);
235
+ process.exit(0);
236
+ }
237
+ } catch (error) {
238
+ console.error(
239
+ "Error:",
240
+ error instanceof Error ? error.message : String(error)
241
+ );
242
+ process.exit(1);
243
+ }
244
+ }
245
+ if (typeof require !== "undefined" && require.main === module) {
246
+ main();
247
+ }
@@ -0,0 +1,17 @@
1
+ import { BlazeDiffTransformer, BlazeDiffOptions } from '@blazediff/types';
2
+
3
+ interface CompareImagesOptions {
4
+ outputPath?: string;
5
+ transformer: BlazeDiffTransformer;
6
+ coreOptions?: BlazeDiffOptions;
7
+ }
8
+ interface CompareImagesResult {
9
+ diffCount: number;
10
+ width: number;
11
+ height: number;
12
+ outputData?: Uint8Array;
13
+ duration: number;
14
+ }
15
+ declare function compareImages(image1Path: string, image2Path: string, options: CompareImagesOptions): Promise<CompareImagesResult>;
16
+
17
+ export { type CompareImagesOptions, type CompareImagesResult, compareImages };
@@ -0,0 +1,17 @@
1
+ import { BlazeDiffTransformer, BlazeDiffOptions } from '@blazediff/types';
2
+
3
+ interface CompareImagesOptions {
4
+ outputPath?: string;
5
+ transformer: BlazeDiffTransformer;
6
+ coreOptions?: BlazeDiffOptions;
7
+ }
8
+ interface CompareImagesResult {
9
+ diffCount: number;
10
+ width: number;
11
+ height: number;
12
+ outputData?: Uint8Array;
13
+ duration: number;
14
+ }
15
+ declare function compareImages(image1Path: string, image2Path: string, options: CompareImagesOptions): Promise<CompareImagesResult>;
16
+
17
+ export { type CompareImagesOptions, type CompareImagesResult, compareImages };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var s=require('@blazediff/core');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var s__default=/*#__PURE__*/_interopDefault(s);async function d(i,n,r){let[t,e]=await Promise.all([r.transformer.transform(i),r.transformer.transform(n)]);if(t.width!==e.width||t.height!==e.height)throw new Error(`Image dimensions do not match: ${t.width}x${t.height} vs ${e.width}x${e.height}`);let a;r.outputPath&&(a=new Uint8Array(t.data.length));let o=performance.now(),m=s__default.default(t.data,e.data,a,t.width,t.height,r.coreOptions),f=performance.now()-o;return {diffCount:m,width:t.width,height:t.height,outputData:a,duration:f}}exports.compareImages=d;
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import s from'@blazediff/core';async function d(i,n,r){let[t,e]=await Promise.all([r.transformer.transform(i),r.transformer.transform(n)]);if(t.width!==e.width||t.height!==e.height)throw new Error(`Image dimensions do not match: ${t.width}x${t.height} vs ${e.width}x${e.height}`);let a;r.outputPath&&(a=new Uint8Array(t.data.length));let o=performance.now(),m=s(t.data,e.data,a,t.width,t.height,r.coreOptions),f=performance.now()-o;return {diffCount:m,width:t.width,height:t.height,outputData:a,duration:f}}export{d as compareImages};
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@blazediff/bin",
3
+ "version": "0.0.1",
4
+ "description": "Command-line interface for the blazediff image comparison library",
5
+ "private": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "main": "dist/index.js",
10
+ "module": "dist/index.mjs",
11
+ "types": "dist/index.d.ts",
12
+ "bin": {
13
+ "blazediff": "./dist/cli.js"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.mjs",
19
+ "require": "./dist/index.js"
20
+ },
21
+ "./cli": {
22
+ "import": "./dist/cli.mjs",
23
+ "require": "./dist/cli.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "keywords": [
30
+ "cli",
31
+ "image",
32
+ "comparison",
33
+ "diff"
34
+ ],
35
+ "author": "Teimur Gasanov <me@teimurjan.dev> (https://github.com/teimurjan)",
36
+ "repository": "https://github.com/teimurjan/blazediff",
37
+ "homepage": "https://github.com/teimurjan/blazediff",
38
+ "license": "MIT",
39
+ "dependencies": {
40
+ "@blazediff/core": "0.0.1",
41
+ "@blazediff/pngjs-transformer": "0.0.1",
42
+ "@blazediff/sharp-transformer": "0.0.1"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^24.3.0",
46
+ "tsup": "8.5.0",
47
+ "typescript": "5.9.2",
48
+ "@blazediff/types": "0.0.1"
49
+ },
50
+ "scripts": {
51
+ "build": "tsup",
52
+ "dev": "tsup --watch",
53
+ "clean": "rm -rf dist"
54
+ }
55
+ }