sharp-phash
Advanced tools
Comparing version 1.0.2 to 1.1.0
14
index.js
@@ -8,3 +8,3 @@ "use strict"; | ||
function initSQRT(N) { | ||
let c = new Array(N); | ||
const c = new Array(N); | ||
for (let i = 1; i < N; i++) { | ||
@@ -20,3 +20,3 @@ c[i] = 1; | ||
function initCOS(N) { | ||
let cosines = new Array(N); | ||
const cosines = new Array(N); | ||
for (let k = 0; k < N; k++) { | ||
@@ -55,4 +55,4 @@ cosines[k] = new Array(N); | ||
module.exports = async function phash(image) { | ||
const data = await sharp(image) | ||
module.exports = async function phash(image, opts = { sharp: sharp }) { | ||
const data = await opts.sharp(image) | ||
.greyscale() | ||
@@ -64,3 +64,3 @@ .resize(SAMPLE_SIZE, SAMPLE_SIZE, { fit: "fill" }) | ||
// copy signal | ||
let s = new Array(SAMPLE_SIZE); | ||
const s = new Array(SAMPLE_SIZE); | ||
for (let x = 0; x < SAMPLE_SIZE; x++) { | ||
@@ -74,3 +74,3 @@ s[x] = new Array(SAMPLE_SIZE); | ||
// apply 2D DCT II | ||
let dct = applyDCT(s, SAMPLE_SIZE); | ||
const dct = applyDCT(s, SAMPLE_SIZE); | ||
@@ -85,3 +85,3 @@ // get AVG on high frequencies | ||
let avg = totalSum / (LOW_SIZE * LOW_SIZE); | ||
const avg = totalSum / (LOW_SIZE * LOW_SIZE); | ||
@@ -88,0 +88,0 @@ // compute hash |
{ | ||
"name": "sharp-phash", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "sharp based perceptual hash implementation", | ||
@@ -20,14 +20,14 @@ "main": "index.js", | ||
], | ||
"author": "", | ||
"author": "Denis Bardadym <bardadymchik@gmail.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"sharp": "^0.22.0" | ||
"sharp": "^0.25.4" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.16.0", | ||
"eslint-plugin-promise": "^4.1.1" | ||
"eslint": "^7.2.0", | ||
"eslint-plugin-promise": "^4.2.1" | ||
}, | ||
"engines": { | ||
"node": ">= 8.10" | ||
"node": ">= 10" | ||
} | ||
} |
@@ -34,1 +34,11 @@ # sharp-phash | ||
``` | ||
## Your own sharp version | ||
```js | ||
const sharp = require('sharp'); | ||
const phash = require('sharp-phash'); | ||
phash(..., { sharp }) | ||
``` |
26
test.js
@@ -28,3 +28,3 @@ /* eslint-disable no-console */ | ||
function getPHash(img) { | ||
return fs.readFile(path.join(".", "img", img)).then(buf => phash(buf)); | ||
return fs.readFile(path.join(".", "img", img)).then((buf) => phash(buf)); | ||
} | ||
@@ -37,5 +37,6 @@ | ||
function testCase(img1, img2, cond) { | ||
return Promise.all([getPHash(img1), getPHash(img2)]).then(([hash1, hash2]) => { | ||
const d = dist(hash1, hash2); | ||
const text = `${img1} vs ${img2} | ||
return Promise.all([getPHash(img1), getPHash(img2)]).then( | ||
([hash1, hash2]) => { | ||
const d = dist(hash1, hash2); | ||
const text = `${img1} vs ${img2} | ||
hash1: ${hash1} (${bitCount(hash1)}) | ||
@@ -45,10 +46,11 @@ hash2: ${hash2} (${bitCount(hash2)}) | ||
`; | ||
assert.ok(cond(d), text); | ||
console.log("Test PASS", img1, img2, cond.name); | ||
}); | ||
assert.ok(cond(d), text); | ||
console.log("Test PASS", img1, img2, cond.name); | ||
} | ||
); | ||
} | ||
const SIMILAR = d => d <= 5; | ||
const LIKELY_SIMILAR = d => d <= 10; | ||
const NOT_SIMILAR = d => d > 10; | ||
const SIMILAR = (d) => d <= 5; | ||
const LIKELY_SIMILAR = (d) => d <= 10; | ||
const NOT_SIMILAR = (d) => d > 10; | ||
@@ -63,6 +65,6 @@ Promise.all([ | ||
testCase(fb3, fb4, NOT_SIMILAR), | ||
testCase(fb5, fb6, NOT_SIMILAR) | ||
]).catch(err => { | ||
testCase(fb5, fb6, NOT_SIMILAR), | ||
]).catch((err) => { | ||
console.log("Test fail"); | ||
console.log(err.message); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
6338
141
1
44
+ Addedchownr@2.0.0(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedmimic-response@3.1.0(transitive)
+ Addedminipass@3.3.65.0.0(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addednode-addon-api@3.2.1(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedsharp@0.25.4(transitive)
+ Addedsimple-get@4.0.1(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedyallist@4.0.0(transitive)
- Removedfs-copy-file-sync@1.1.1(transitive)
- Removedfs-minipass@1.2.7(transitive)
- Removedminipass@2.9.0(transitive)
- Removedminizlib@1.3.3(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednan@2.22.0(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsemver@6.3.1(transitive)
- Removedsharp@0.22.1(transitive)
- Removedtar@4.4.19(transitive)
- Removedyallist@3.1.1(transitive)
Updatedsharp@^0.25.4