Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sharp-phash

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sharp-phash - npm Package Compare versions

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 })
```

@@ -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);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc