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 0.2.2 to 1.0.0

15

index.js

@@ -1,7 +0,5 @@

'use strict';
"use strict";
const sharp = require('sharp');
const Promise = require('bluebird');
const sharp = require("sharp");
const SAMPLE_SIZE = 32;

@@ -12,3 +10,3 @@

for(let i = 1; i < N; i++) {
c[i]=1;
c[i] = 1;
}

@@ -19,3 +17,2 @@ c[0] = 1 / Math.sqrt(2.0);

const SQRT = initSQRT(SAMPLE_SIZE);

@@ -49,3 +46,3 @@

}
sum *= ((SQRT[u] * SQRT[v]) / 4);
sum *= (SQRT[u] * SQRT[v]) / 4;
F[u][v] = sum;

@@ -59,3 +56,2 @@ }

module.exports = function phash(image) {

@@ -73,3 +69,2 @@ return new Promise((resolve, reject) => {

} else {
// copy signal

@@ -98,3 +93,3 @@ let s = new Array(SAMPLE_SIZE);

// compute hash
let fingerprint = '';
let fingerprint = "";

@@ -101,0 +96,0 @@ for(let x = 0; x < LOW_SIZE; x++) {

{
"name": "sharp-phash",
"version": "0.2.2",
"version": "1.0.0",
"description": "sharp based perceptual hash implementation",

@@ -23,3 +23,2 @@ "main": "index.js",

"dependencies": {
"bluebird": "^3.5.1",
"sharp": "^0.20.5"

@@ -26,0 +25,0 @@ },

@@ -1,13 +0,12 @@

'use strict';
"use strict";
const fs = require('fs');
const path = require('path');
const Promise = require('bluebird');
const fs = require("fs");
const path = require("path");
const assert = require('assert');
const assert = require("assert");
const phash = require('./index');
const dist = require('./distance');
const phash = require("./index");
const dist = require("./distance");
const readFile = (fileName) => {
const readFile = fileName => {
return new Promise((resolve, reject) => {

@@ -24,35 +23,29 @@ fs.readFile(fileName, (err, res) => {

const lenna_png = 'Lenna.png';
const lenna_jpg = 'Lenna.jpg';
const lenna_sepia = 'Lenna-sepia.jpg';
const lenna_exif = 'Lenna_exif-orientation-8.jpg';
const lenna_png = "Lenna.png";
const lenna_jpg = "Lenna.jpg";
const lenna_sepia = "Lenna-sepia.jpg";
const lenna_exif = "Lenna_exif-orientation-8.jpg";
const fb = "fb.jpg";
const xing = "xing.jpg";
const fb = 'fb.jpg';
const xing = 'xing.jpg';
const fb1 = "fb1.jpg";
const fb2 = "fb2.jpg";
const fb3 = "fb3.jpg";
const fb4 = "fb4.jpg";
const fb5 = "fb5.jpg";
const fb6 = "fb6.jpg";
const fb1 = 'fb1.jpg';
const fb2 = 'fb2.jpg';
const fb3 = 'fb3.jpg';
const fb4 = 'fb4.jpg';
const fb5 = 'fb5.jpg';
const fb6 = 'fb6.jpg';
function getPHash(img) {
return readFile(path.join('.', 'img', img))
.then(buf => phash(buf));
return readFile(path.join(".", "img", img)).then(buf => phash(buf));
}
function bitCount(hash) {
return hash.replace(/0/g, '').length;
return hash.replace(/0/g, "").length;
}
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)})

@@ -62,9 +55,9 @@ hash2: ${hash2} (${bitCount(hash2)})

`;
assert.ok(cond(d), text);
});
assert.ok(cond(d), text);
});
}
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;

@@ -79,7 +72,6 @@ Promise.all([

testCase(fb3, fb4, NOT_SIMILAR),
testCase(fb5, fb6, NOT_SIMILAR),
])
.catch(err => {
console.log('Test fail');
console.log(err.message);
});
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