friendly-img-hash-js 1.0.1 → 1.0.3
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 +2 -2
- package/index.js +21 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# friendly-
|
|
1
|
+
# friendly-img-hash-js
|
|
2
2
|
|
|
3
3
|
A js implementation of https://docs.rs/img_hash/ which itself is based on the work of http://www.hackerfactor.com/.
|
|
4
4
|
|
|
@@ -132,7 +132,7 @@ const config = { output: Convert.options.BigInt };
|
|
|
132
132
|
const result1 = hash(image1, config);
|
|
133
133
|
const result2 = hash(image2, config);
|
|
134
134
|
|
|
135
|
-
if (leven(result1, result2) <= 12) {
|
|
135
|
+
if (leven(result1.toString(), result2.toString()) <= 12) {
|
|
136
136
|
console.log ('Images are very similar!');
|
|
137
137
|
}
|
|
138
138
|
```
|
package/index.js
CHANGED
|
@@ -10,5 +10,25 @@ export {
|
|
|
10
10
|
// See defaultConfig for options.
|
|
11
11
|
export const hash = async (img, userConfig) => {
|
|
12
12
|
const image = await JIMP.read(img);
|
|
13
|
-
|
|
13
|
+
const bytes = reduceToRgb(image.bitmap.data, image.bitmap.width, image.bitmap.height);
|
|
14
|
+
return coreHash(bytes, image.bitmap.width, image.bitmap.height, userConfig);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const reduceToRgb = (data, width, height) => {
|
|
18
|
+
// already rgb
|
|
19
|
+
if (data.length === (width * height * 3)) {
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// rgba
|
|
24
|
+
if (data.length === (width * height * 4)) {
|
|
25
|
+
return data.filter((_, i) => (i + 1) % 4);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// l8
|
|
29
|
+
if (data.length === (width * height)) {
|
|
30
|
+
return new Array(width * height * 3).fill(0).map((_, i) => data[Math.floor(i / 3)]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
throw new Error(`Unknown data length, expected ${data.length} to be a factor of width * height (${width} * ${height}).`);
|
|
14
34
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "friendly-img-hash-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "User friendly algorithms for generating image hashes.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"mocha": "^10.2.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"img-hash-js-core": "^1.0.
|
|
40
|
+
"img-hash-js-core": "^1.0.7",
|
|
41
41
|
"jimp": "^0.22.10"
|
|
42
42
|
}
|
|
43
43
|
}
|