New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

img-hasher

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

img-hasher - npm Package Compare versions

Comparing version

to
0.0.5

136

index.d.ts

@@ -19,62 +19,62 @@ /* tslint:disable */

export const enum HashAlgorithm {
/**
* The Mean hashing algorithm.
*
* The image is converted to grayscale, scaled down to `hash_width x hash_height`,
* the mean pixel value is taken, and then the hash bits are generated by comparing
* the pixels of the descaled image to the mean.
*
* This is the most basic hash algorithm supported, resistant only to changes in
* resolution, aspect ratio, and overall brightness.
*
* Further Reading:
* http://www.hackerfactor.com/blog/?/archives/432-Looks-Like-It.html
*/
Mean = 0,
/**
* The Gradient hashing algorithm.
*
* The image is converted to grayscale, scaled down to `(hash_width + 1) x hash_height`,
* and then in row-major order the pixels are compared with each other, setting bits
* in the hash for each comparison. The extra pixel is needed to have `hash_width` comparisons
* per row.
*
* This hash algorithm is as fast or faster than Mean (because it only traverses the
* hash data once) and is more resistant to changes than Mean.
*
* Further Reading:
* http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
*/
Gradient = 1,
/**
* The Vertical-Gradient hashing algorithm.
*
* Equivalent to [`Gradient`](#variant.Gradient) but operating on the columns of the image
* instead of the rows.
*/
VertGradient = 2,
/**
* The Double-Gradient hashing algorithm.
*
* An advanced version of [`Gradient`](#variant.Gradient);
* resizes the grayscaled image to `(width / 2 + 1) x (height / 2 + 1)` and compares columns
* in addition to rows.
*
* This algorithm is slightly slower than `Gradient` (resizing the image dwarfs
* the hash time in most cases) but the extra comparison direction may improve results (though
* you might want to consider increasing
* [`hash_size`](struct.HasherConfig.html#method.hash_size)
* to accommodate the extra comparisons).
*/
DoubleGradient = 3,
/**
* The [Blockhash.io](https://blockhash.io) algorithm.
*
* Compared to the other algorithms, this does not require any preprocessing steps and so
* may be significantly faster at the cost of some resilience.
*
* The algorithm is described in a high level here:
* https://github.com/commonsmachinery/blockhash-rfc/blob/master/main.md
*/
Blockhash = 4
/**
* The Mean hashing algorithm.
*
* The image is converted to grayscale, scaled down to `hash_width x hash_height`,
* the mean pixel value is taken, and then the hash bits are generated by comparing
* the pixels of the descaled image to the mean.
*
* This is the most basic hash algorithm supported, resistant only to changes in
* resolution, aspect ratio, and overall brightness.
*
* Further Reading:
* http://www.hackerfactor.com/blog/?/archives/432-Looks-Like-It.html
*/
Mean = 0,
/**
* The Gradient hashing algorithm.
*
* The image is converted to grayscale, scaled down to `(hash_width + 1) x hash_height`,
* and then in row-major order the pixels are compared with each other, setting bits
* in the hash for each comparison. The extra pixel is needed to have `hash_width` comparisons
* per row.
*
* This hash algorithm is as fast or faster than Mean (because it only traverses the
* hash data once) and is more resistant to changes than Mean.
*
* Further Reading:
* http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
*/
Gradient = 1,
/**
* The Vertical-Gradient hashing algorithm.
*
* Equivalent to [`Gradient`](#variant.Gradient) but operating on the columns of the image
* instead of the rows.
*/
VertGradient = 2,
/**
* The Double-Gradient hashing algorithm.
*
* An advanced version of [`Gradient`](#variant.Gradient);
* resizes the grayscaled image to `(width / 2 + 1) x (height / 2 + 1)` and compares columns
* in addition to rows.
*
* This algorithm is slightly slower than `Gradient` (resizing the image dwarfs
* the hash time in most cases) but the extra comparison direction may improve results (though
* you might want to consider increasing
* [`hash_size`](struct.HasherConfig.html#method.hash_size)
* to accommodate the extra comparisons).
*/
DoubleGradient = 3,
/**
* The [Blockhash.io](https://blockhash.io) algorithm.
*
* Compared to the other algorithms, this does not require any preprocessing steps and so
* may be significantly faster at the cost of some resilience.
*
* The algorithm is described in a high level here:
* https://github.com/commonsmachinery/blockhash-rfc/blob/master/main.md
*/
Blockhash = 4,
}

@@ -90,7 +90,7 @@ /**

* ```js
* const { getHash } = require('image-distance');
* const { getHash } = require('img-hasher');
* const hash = await getHash('https://example.com/image.jpg');
* ```
*/
export function getHash(input: Buffer | string, hashAlgo?: HashAlgorithm | undefined | null): Promise<void>
export function getHash(input: Buffer | string, hashAlgo?: HashAlgorithm | undefined | null): Promise<void>;
/**

@@ -105,3 +105,3 @@ * get hamming distance of two image hashes

* ```js
* const { getHash, hammingDistanceFromHash } = require('image-distance');
* const { getHash, hammingDistanceFromHash } = require('img-hasher');
* const hash1 = await getHash('https://example.com/image1.jpg');

@@ -112,3 +112,3 @@ * const hash2 = await getHash('https://example.com/image2.jpg');

*/
export function hammingDistanceFromHash(input1: string, input2: string): Promise<void>
export function hammingDistanceFromHash(input1: string, input2: string): Promise<void>;
/**

@@ -124,6 +124,10 @@ * get hamming distance of two images

* ```js
* const { hammingDistance } = require('image-distance');
* const { hammingDistance } = require('img-hasher');
* const distance = await hammingDistance('https://example.com/image1.jpg', 'https://example.com/image2.jpg');
* ```
*/
export function hammingDistance(input1: Buffer | string, input2: Buffer | string, hashAlgo?: HashAlgorithm | undefined | null): Promise<void>
export function hammingDistance(
input1: Buffer | string,
input2: Buffer | string,
hashAlgo?: HashAlgorithm | undefined | null,
): Promise<void>;

@@ -8,254 +8,236 @@ /* tslint:disable */

const { existsSync, readFileSync } = require('fs')
const { join } = require('path')
const { join } = require('path');
const { platform, arch } = process
const { platform, arch } = process;
let nativeBinding = null
let localFileExisted = false
let loadError = null
let nativeBinding = null;
let localFileExisted = false;
let loadError = null;
function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
const lddPath = require('child_process').execSync('which ldd').toString().trim();
return readFileSync(lddPath, 'utf8').includes('musl')
} catch (e) {
return true
}
} else {
const { glibcVersionRuntime } = process.report.getReport().header
return !glibcVersionRuntime
}
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
const lddPath = require('child_process').execSync('which ldd').toString().trim();
return readFileSync(lddPath, 'utf8').includes('musl');
} catch (e) {
return true;
}
} else {
const { glibcVersionRuntime } = process.report.getReport().header;
return !glibcVersionRuntime;
}
}
switch (platform) {
case 'android':
switch (arch) {
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'img-hasher.android-arm64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.android-arm64.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-android-arm64')
}
} catch (e) {
loadError = e
}
break
case 'arm':
localFileExisted = existsSync(join(__dirname, 'img-hasher.android-arm-eabi.node'))
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.android-arm-eabi.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-android-arm-eabi')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Android ${arch}`)
}
break
case 'win32':
switch (arch) {
case 'x64':
localFileExisted = existsSync(
join(__dirname, 'img-hasher.win32-x64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.win32-x64-msvc.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-win32-x64-msvc')
}
} catch (e) {
loadError = e
}
break
case 'ia32':
localFileExisted = existsSync(
join(__dirname, 'img-hasher.win32-ia32-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.win32-ia32-msvc.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-win32-ia32-msvc')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'img-hasher.win32-arm64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.win32-arm64-msvc.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-win32-arm64-msvc')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`)
}
break
case 'darwin':
localFileExisted = existsSync(join(__dirname, 'img-hasher.darwin-universal.node'))
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.darwin-universal.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-darwin-universal')
}
break
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'img-hasher.darwin-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.darwin-x64.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-darwin-x64')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'img-hasher.darwin-arm64.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.darwin-arm64.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-darwin-arm64')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on macOS: ${arch}`)
}
break
case 'freebsd':
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
}
localFileExisted = existsSync(join(__dirname, 'img-hasher.freebsd-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.freebsd-x64.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-freebsd-x64')
}
} catch (e) {
loadError = e
}
break
case 'linux':
switch (arch) {
case 'x64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'img-hasher.linux-x64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.linux-x64-musl.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-linux-x64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'img-hasher.linux-x64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.linux-x64-gnu.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-linux-x64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'img-hasher.linux-arm64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.linux-arm64-musl.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-linux-arm64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'img-hasher.linux-arm64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.linux-arm64-gnu.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-linux-arm64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm':
localFileExisted = existsSync(
join(__dirname, 'img-hasher.linux-arm-gnueabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.linux-arm-gnueabihf.node')
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-linux-arm-gnueabihf')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
break
default:
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
case 'android':
switch (arch) {
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'img-hasher.android-arm64.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.android-arm64.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-android-arm64');
}
} catch (e) {
loadError = e;
}
break;
case 'arm':
localFileExisted = existsSync(join(__dirname, 'img-hasher.android-arm-eabi.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.android-arm-eabi.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-android-arm-eabi');
}
} catch (e) {
loadError = e;
}
break;
default:
throw new Error(`Unsupported architecture on Android ${arch}`);
}
break;
case 'win32':
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'img-hasher.win32-x64-msvc.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.win32-x64-msvc.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-win32-x64-msvc');
}
} catch (e) {
loadError = e;
}
break;
case 'ia32':
localFileExisted = existsSync(join(__dirname, 'img-hasher.win32-ia32-msvc.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.win32-ia32-msvc.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-win32-ia32-msvc');
}
} catch (e) {
loadError = e;
}
break;
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'img-hasher.win32-arm64-msvc.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.win32-arm64-msvc.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-win32-arm64-msvc');
}
} catch (e) {
loadError = e;
}
break;
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`);
}
break;
case 'darwin':
localFileExisted = existsSync(join(__dirname, 'img-hasher.darwin-universal.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.darwin-universal.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-darwin-universal');
}
break;
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'img-hasher.darwin-x64.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.darwin-x64.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-darwin-x64');
}
} catch (e) {
loadError = e;
}
break;
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'img-hasher.darwin-arm64.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.darwin-arm64.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-darwin-arm64');
}
} catch (e) {
loadError = e;
}
break;
default:
throw new Error(`Unsupported architecture on macOS: ${arch}`);
}
break;
case 'freebsd':
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
}
localFileExisted = existsSync(join(__dirname, 'img-hasher.freebsd-x64.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.freebsd-x64.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-freebsd-x64');
}
} catch (e) {
loadError = e;
}
break;
case 'linux':
switch (arch) {
case 'x64':
if (isMusl()) {
localFileExisted = existsSync(join(__dirname, 'img-hasher.linux-x64-musl.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.linux-x64-musl.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-linux-x64-musl');
}
} catch (e) {
loadError = e;
}
} else {
localFileExisted = existsSync(join(__dirname, 'img-hasher.linux-x64-gnu.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.linux-x64-gnu.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-linux-x64-gnu');
}
} catch (e) {
loadError = e;
}
}
break;
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(join(__dirname, 'img-hasher.linux-arm64-musl.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.linux-arm64-musl.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-linux-arm64-musl');
}
} catch (e) {
loadError = e;
}
} else {
localFileExisted = existsSync(join(__dirname, 'img-hasher.linux-arm64-gnu.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.linux-arm64-gnu.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-linux-arm64-gnu');
}
} catch (e) {
loadError = e;
}
}
break;
case 'arm':
localFileExisted = existsSync(join(__dirname, 'img-hasher.linux-arm-gnueabihf.node'));
try {
if (localFileExisted) {
nativeBinding = require('./img-hasher.linux-arm-gnueabihf.node');
} else {
nativeBinding = require('@imranbarbhuiya/img-hasher-linux-arm-gnueabihf');
}
} catch (e) {
loadError = e;
}
break;
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`);
}
break;
default:
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
}
if (!nativeBinding) {
if (loadError) {
throw loadError
}
throw new Error(`Failed to load native binding`)
if (loadError) {
throw loadError;
}
throw new Error(`Failed to load native binding`);
}
const { HashAlgorithm, getHash, hammingDistanceFromHash, hammingDistance } = nativeBinding
const { HashAlgorithm, getHash, hammingDistanceFromHash, hammingDistance } = nativeBinding;
module.exports.HashAlgorithm = HashAlgorithm
module.exports.getHash = getHash
module.exports.hammingDistanceFromHash = hammingDistanceFromHash
module.exports.hammingDistance = hammingDistance
module.exports.HashAlgorithm = HashAlgorithm;
module.exports.getHash = getHash;
module.exports.hammingDistanceFromHash = hammingDistanceFromHash;
module.exports.hammingDistance = hammingDistance;
{
"name": "img-hasher",
"description": "A fast image hash generator and hamming distance calculator using multiple algorithms",
"version": "0.0.4",
"version": "0.0.5",
"main": "index.js",

@@ -26,3 +26,4 @@ "types": "index.d.ts",

"universal": "napi universal",
"version": "napi version"
"version": "napi version && yarn format",
"format": "prettier --write . --ignore-unknown"
},

@@ -32,4 +33,2 @@ "devDependencies": {

"@types/node": "^20.1.4",
"eslint": "^8.40.0",
"eslint-config-mahir": "^0.0.26",
"prettier": "^2.8.8"

@@ -57,10 +56,10 @@ },

"packageManager": "yarn@3.5.1",
"repository": "https://github.com/imranbarbhuiya/image-distance",
"repository": "https://github.com/imranbarbhuiya/img-hasher",
"optionalDependencies": {
"@imranbarbhuiya/img-hasher-win32-x64-msvc": "0.0.4",
"@imranbarbhuiya/img-hasher-darwin-x64": "0.0.4",
"@imranbarbhuiya/img-hasher-linux-x64-gnu": "0.0.4",
"@imranbarbhuiya/img-hasher-darwin-arm64": "0.0.4",
"@imranbarbhuiya/img-hasher-linux-x64-musl": "0.0.4"
"@imranbarbhuiya/img-hasher-win32-x64-msvc": "0.0.5",
"@imranbarbhuiya/img-hasher-darwin-x64": "0.0.5",
"@imranbarbhuiya/img-hasher-linux-x64-gnu": "0.0.5",
"@imranbarbhuiya/img-hasher-darwin-arm64": "0.0.5",
"@imranbarbhuiya/img-hasher-linux-x64-musl": "0.0.5"
}
}

@@ -0,0 +0,0 @@ # Image Hasher