image-hash 3.4.1 → 5.0.2
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 +48 -11
- package/lib/imageHash.d.ts +11 -1
- package/lib/imageHash.js +90 -29
- package/lib/imageHash.js.map +1 -1
- package/package.json +13 -7
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# image-hash
|
|
2
2
|
A wrapper around [block-hash](https://github.com/commonsmachinery/blockhash-js) to easily hash a local or remote file with Node.
|
|
3
3
|
|
|
4
|
-
Supports JPG and
|
|
4
|
+
Supports JPG, PNG and WebP
|
|
5
5
|
|
|
6
6
|
## Install
|
|
7
7
|
```bash
|
|
@@ -36,6 +36,27 @@ imageHash('./_95695590_tv039055678.jpg', 16, true, (error, data) => {
|
|
|
36
36
|
console.log(data);
|
|
37
37
|
// 0773063f063f36070e070a070f378e7f1f000fff0fff020103f00ffb0f810ff0
|
|
38
38
|
});
|
|
39
|
+
|
|
40
|
+
//Buffer
|
|
41
|
+
const fBuffer = fs.readFileSync(__dirname + '/example/_95695591_tv039055678.jpeg');
|
|
42
|
+
imageHash({
|
|
43
|
+
ext: 'image/jpeg',
|
|
44
|
+
data: fBuffer
|
|
45
|
+
}, 16, true, (error, data) => {
|
|
46
|
+
if(error) throw error;
|
|
47
|
+
console.log(data);
|
|
48
|
+
// 0773063f063f36070e070a070f378e7f1f000fff0fff020103f00ffb0f810ff0
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
//Buffer, without ext arg
|
|
52
|
+
const fBuffer = fs.readFileSync(__dirname + '/example/_95695591_tv039055678.jpeg');
|
|
53
|
+
imageHash({
|
|
54
|
+
data: fBuffer
|
|
55
|
+
}, 16, true, (error, data) => {
|
|
56
|
+
if(error) throw error;
|
|
57
|
+
console.log(data);
|
|
58
|
+
// 0773063f063f36070e070a070f378e7f1f000fff0fff020103f00ffb0f810ff0
|
|
59
|
+
});
|
|
39
60
|
```
|
|
40
61
|
|
|
41
62
|
## API
|
|
@@ -49,19 +70,35 @@ imageHash(string|object, int, bool, function)
|
|
|
49
70
|
|
|
50
71
|
### Image-Hash Arguments
|
|
51
72
|
|
|
52
|
-
Argument | Type
|
|
53
|
-
|
|
54
|
-
location | `object` or `string` | A [RequestJS Object](https://github.com/request/request#requestoptions-callback) or `String` with a valid url or file location
|
|
55
|
-
bits
|
|
56
|
-
precise
|
|
57
|
-
callback | `function`
|
|
73
|
+
| Argument | Type | Description | Mandatory | Example |
|
|
74
|
+
| -------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------- | --------- |
|
|
75
|
+
| location | `object` or `string` | A [RequestJS Object](https://github.com/request/request#requestoptions-callback), `Buffer` object (See input types below for more details), or `String` with a valid url or file location | Yes | see above |
|
|
76
|
+
| bits | `int` | The number of bits in a row. The more bits, the more unique the hash. | Yes | 8 |
|
|
77
|
+
| precise | `bool` | Whether a precision algorithm is used. `true` Precise but slower, non-overlapping blocks. `false` Quick and crude, non-overlapping blocks. Method 2 is recommended as a good tradeoff between speed and good matches on any image size. The quick ones are only advisable when the image width and height are an even multiple of the number of blocks used. | Yes | `true` |
|
|
78
|
+
| callback | `function` | A function with `error` and `data` arguments - see below |
|
|
79
|
+
|
|
80
|
+
#### Location Object Types
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// Url Request Object
|
|
84
|
+
interface UrlRequestObject {
|
|
85
|
+
encoding?: string | null,
|
|
86
|
+
url: string | null,
|
|
87
|
+
};
|
|
88
|
+
// Buffer Object
|
|
89
|
+
interface BufferObject {
|
|
90
|
+
ext?: string, // mime type of buffered file
|
|
91
|
+
data: Buffer,
|
|
92
|
+
name?: string // file name for buffered file
|
|
93
|
+
};
|
|
94
|
+
```
|
|
58
95
|
|
|
59
96
|
### Callback Arguments
|
|
60
97
|
|
|
61
|
-
Argument | Type
|
|
62
|
-
|
|
63
|
-
error
|
|
64
|
-
data
|
|
98
|
+
| Argument | Type | Description |
|
|
99
|
+
| -------- | ------------------------ | ----------------------------------------------------------------------------------- | | |
|
|
100
|
+
| error | `Error Object` or `null` | If a run time error is detected this will be an `Error Object`, otherwise `null` |
|
|
101
|
+
| data | `string` or `null` | If there is no run time error, this be will be your hashed result, otherwise `null` |
|
|
65
102
|
|
|
66
103
|
## Development
|
|
67
104
|
I have made this with Typescript, ESLint, Jest, Babel and VSCode. All config files and global binaries are included. For developers using VS Code, make sure you have ESLint extension installed.
|
package/lib/imageHash.d.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export interface UrlRequestObject {
|
|
3
|
+
encoding?: string | null;
|
|
4
|
+
url: string | null;
|
|
5
|
+
}
|
|
6
|
+
export interface BufferObject {
|
|
7
|
+
ext?: string;
|
|
8
|
+
data: Buffer;
|
|
9
|
+
name?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const imageHash: (oldSrc: string | UrlRequestObject | BufferObject, bits: any, method: any, cb: any) => void;
|
package/lib/imageHash.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
2
10
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
11
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
12
|
};
|
|
5
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
14
|
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
const buffer_1 = require("buffer");
|
|
7
16
|
const file_type_1 = __importDefault(require("file-type"));
|
|
8
17
|
const jpeg_js_1 = __importDefault(require("jpeg-js"));
|
|
9
18
|
const pngjs_1 = require("pngjs");
|
|
10
19
|
const request_1 = __importDefault(require("request"));
|
|
11
|
-
const block_hash_1 = __importDefault(require("./block-hash"));
|
|
12
20
|
const url_1 = require("url");
|
|
21
|
+
const block_hash_1 = __importDefault(require("./block-hash"));
|
|
22
|
+
const webp_1 = __importDefault(require("@cwasm/webp"));
|
|
13
23
|
const processPNG = (data, bits, method, cb) => {
|
|
14
24
|
try {
|
|
15
25
|
const png = pngjs_1.PNG.sync.read(data);
|
|
@@ -30,43 +40,90 @@ const processJPG = (data, bits, method, cb) => {
|
|
|
30
40
|
cb(e);
|
|
31
41
|
}
|
|
32
42
|
};
|
|
43
|
+
const processWebp = (data, bits, method, cb) => {
|
|
44
|
+
try {
|
|
45
|
+
const decoded = webp_1.default.decode(data);
|
|
46
|
+
const res = block_hash_1.default(decoded, bits, method ? 2 : 1);
|
|
47
|
+
cb(null, res);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
cb(e);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const isUrlRequestObject = (obj) => {
|
|
54
|
+
const casted = obj;
|
|
55
|
+
return casted.url && casted.url.length > 0;
|
|
56
|
+
};
|
|
57
|
+
const isBufferObject = (obj) => {
|
|
58
|
+
const casted = obj;
|
|
59
|
+
return buffer_1.Buffer.isBuffer(casted.data)
|
|
60
|
+
|| (buffer_1.Buffer.isBuffer(casted.data) && (casted.ext && casted.ext.length > 0));
|
|
61
|
+
};
|
|
33
62
|
// eslint-disable-next-line
|
|
34
63
|
exports.imageHash = (oldSrc, bits, method, cb) => {
|
|
35
64
|
const src = oldSrc;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return;
|
|
65
|
+
const getFileType = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
if (typeof src !== 'string' && isBufferObject(src) && src.ext) {
|
|
67
|
+
return {
|
|
68
|
+
mime: src.ext,
|
|
69
|
+
};
|
|
42
70
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.
|
|
46
|
-
.pop()
|
|
47
|
-
.toLowerCase();
|
|
48
|
-
if (ext === 'png' && type.mime === 'image/png') {
|
|
49
|
-
processPNG(data, bits, method, cb);
|
|
50
|
-
}
|
|
51
|
-
else if ((ext === 'jpg' || ext === 'jpeg') && type.mime === 'image/jpeg') {
|
|
52
|
-
processJPG(data, bits, method, cb);
|
|
71
|
+
try {
|
|
72
|
+
if (buffer_1.Buffer.isBuffer(data)) {
|
|
73
|
+
return yield file_type_1.default.fromBuffer(data);
|
|
53
74
|
}
|
|
54
|
-
|
|
55
|
-
|
|
75
|
+
if (typeof src === 'string') {
|
|
76
|
+
return yield file_type_1.default.fromFile(src);
|
|
56
77
|
}
|
|
78
|
+
return '';
|
|
57
79
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
80
|
+
catch (err) {
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const checkFileType = (name, data) => {
|
|
85
|
+
getFileType(data).then((type) => {
|
|
86
|
+
// what is the image type
|
|
87
|
+
if (!type) {
|
|
88
|
+
cb(new Error('Mime type not found'));
|
|
89
|
+
return;
|
|
62
90
|
}
|
|
63
|
-
|
|
64
|
-
|
|
91
|
+
if (name && name.lastIndexOf('.') > 0) {
|
|
92
|
+
const ext = name
|
|
93
|
+
.split('.')
|
|
94
|
+
.pop()
|
|
95
|
+
.toLowerCase();
|
|
96
|
+
if (ext === 'png' && type.mime === 'image/png') {
|
|
97
|
+
processPNG(data, bits, method, cb);
|
|
98
|
+
}
|
|
99
|
+
else if ((ext === 'jpg' || ext === 'jpeg') && type.mime === 'image/jpeg') {
|
|
100
|
+
processJPG(data, bits, method, cb);
|
|
101
|
+
}
|
|
102
|
+
else if (ext === 'webp' && type.mime === 'image/webp') {
|
|
103
|
+
processWebp(data, bits, method, cb);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
cb(new Error(`Unrecognized file extension, mime type or mismatch, ext: ${ext} / mime: ${type}`));
|
|
107
|
+
}
|
|
65
108
|
}
|
|
66
109
|
else {
|
|
67
|
-
|
|
110
|
+
console.warn('No file extension found, attempting mime typing.');
|
|
111
|
+
if (type.mime === 'image/png') {
|
|
112
|
+
processPNG(data, bits, method, cb);
|
|
113
|
+
}
|
|
114
|
+
else if (type.mime === 'image/jpeg') {
|
|
115
|
+
processJPG(data, bits, method, cb);
|
|
116
|
+
}
|
|
117
|
+
else if (type.mime === 'image/webp') {
|
|
118
|
+
processWebp(data, bits, method, cb);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
cb(new Error(`Unrecognized mime type: ${type}`));
|
|
122
|
+
}
|
|
68
123
|
}
|
|
69
|
-
}
|
|
124
|
+
}).catch((err) => {
|
|
125
|
+
cb(err);
|
|
126
|
+
});
|
|
70
127
|
};
|
|
71
128
|
const handleRequest = (err, res) => {
|
|
72
129
|
if (err) {
|
|
@@ -92,7 +149,7 @@ exports.imageHash = (oldSrc, bits, method, cb) => {
|
|
|
92
149
|
return;
|
|
93
150
|
}
|
|
94
151
|
// is src url or file
|
|
95
|
-
if (typeof src === 'string' && src.indexOf('http') === 0) {
|
|
152
|
+
if (typeof src === 'string' && (src.indexOf('http') === 0 || src.indexOf('https') === 0)) {
|
|
96
153
|
// url
|
|
97
154
|
const req = {
|
|
98
155
|
url: src,
|
|
@@ -100,7 +157,11 @@ exports.imageHash = (oldSrc, bits, method, cb) => {
|
|
|
100
157
|
};
|
|
101
158
|
request_1.default(req, handleRequest);
|
|
102
159
|
}
|
|
103
|
-
else if (typeof src
|
|
160
|
+
else if (typeof src !== 'string' && isBufferObject(src)) {
|
|
161
|
+
// image buffers
|
|
162
|
+
checkFileType(src.name, src.data);
|
|
163
|
+
}
|
|
164
|
+
else if (typeof src !== 'string' && isUrlRequestObject(src)) {
|
|
104
165
|
// Request Object
|
|
105
166
|
src.encoding = null;
|
|
106
167
|
request_1.default(src, handleRequest);
|
package/lib/imageHash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageHash.js","sourceRoot":"","sources":["../src/imageHash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"imageHash.js","sourceRoot":"","sources":["../src/imageHash.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,4CAAoB;AACpB,mCAAgC;AAChC,0DAAiC;AACjC,sDAA2B;AAC3B,iCAA4B;AAC5B,sDAA8B;AAC9B,6BAA0B;AAC1B,8DAAqC;AACrC,uDAA+B;AAE/B,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE;IAC5C,IAAI;QACF,MAAM,GAAG,GAAG,WAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,GAAG,GAAG,oBAAS,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KACf;IAAC,OAAO,CAAC,EAAE;QACV,EAAE,CAAC,CAAC,CAAC,CAAC;KACP;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE;IAC5C,IAAI;QACF,MAAM,OAAO,GAAG,iBAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,GAAG,GAAG,oBAAS,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAA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,GAAG,EAAE,aAAa,CAAC,CAAC;KAC7B;SAAM;QACL,OAAO;QACP,YAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;KAClC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "image-hash",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Create a hash from an image",
|
|
5
5
|
"main": "lib/imageHash.js",
|
|
6
6
|
"types": "lib/imageHash.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "
|
|
9
|
-
"build": "tsc"
|
|
8
|
+
"test": "npx mocha -r ts-node/register __tests__/*.test.ts ",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"lint": "eslint src/*.ts",
|
|
11
|
+
"lint:fix": "eslint src/*.ts --fix"
|
|
10
12
|
},
|
|
11
13
|
"files": [
|
|
12
14
|
"lib"
|
|
@@ -28,26 +30,30 @@
|
|
|
28
30
|
},
|
|
29
31
|
"homepage": "https://github.com/danm/image-hash#readme",
|
|
30
32
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
+
"@cwasm/webp": "^0.1.5",
|
|
34
|
+
"file-type": "^14.6.2",
|
|
35
|
+
"jpeg-js": "^0.4.0",
|
|
33
36
|
"pngjs": "^3.3.3",
|
|
34
37
|
"request": "^2.81.0"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
40
|
+
"@types/chai": "^4.2.12",
|
|
37
41
|
"@babel/cli": "^7.2.3",
|
|
38
42
|
"@babel/core": "^7.2.2",
|
|
39
43
|
"@babel/plugin-transform-modules-commonjs": "^7.4.4",
|
|
40
44
|
"@babel/preset-env": "^7.3.1",
|
|
41
45
|
"@babel/preset-typescript": "^7.1.0",
|
|
42
46
|
"@babel/runtime": "^7.3.1",
|
|
43
|
-
"@types/
|
|
47
|
+
"@types/mocha": "^8.0.0",
|
|
44
48
|
"@types/node": "^11.13.8",
|
|
45
49
|
"@typescript-eslint/eslint-plugin": "^1.7.0",
|
|
46
50
|
"@typescript-eslint/parser": "^1.7.0",
|
|
51
|
+
"chai": "^4.2.0",
|
|
47
52
|
"eslint": "^5.16.0",
|
|
48
53
|
"eslint-config-airbnb-typescript": "^3.0.0",
|
|
49
54
|
"eslint-plugin-import": "^2.17.2",
|
|
50
|
-
"
|
|
55
|
+
"mocha": "^8.1.0",
|
|
56
|
+
"ts-node": "^8.10.2",
|
|
51
57
|
"typescript": "^3.3.1"
|
|
52
58
|
}
|
|
53
59
|
}
|