kkhash
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

Usage

import {kkHash,getBuffer} from 'kkhash';

const run = async()=>{
  // get local picture's buffer;
  const buffer = await getBuffer('./**.jpg'); // or getBuffer('./**.jpg','local')
  // get buffer from internet
  const buffer = await getBuffer('https://www.xxx.com/xx.jpg','http');

  const aHash = await kkHash.getAHash(buffer);
  console.log(`aHash`,aHash) // eg:0010010001100110010011000110011001001100010001000100000101100110
  const pHash = await kkHash.getPHash(buffer);
  const dHash = await kkHash.getDHash(buffer);
  const contHash = await kkHash.getContHash(buffer)
}

run().catch(err=>console.log(err));  // you can use try/catch in your own code

if you don't want to use getBuffer :

import {readFileSync} from 'fs';
import axios from 'axios'
import {kkHash} from 'kkhash';

const run = async()=>{
  const buffer = readFileSync('./**.jpg);
  // or
  const res = await axios.get(`https://www.xxx.com/xx.jpg`, { responseType: `arraybuffer` })
        const buffer = res.data as Buffer
  const aHash = await kkHash.getAHash(buffer);
  const pHash = await kkHash.getPHash(buffer);
  const dHash = await kkHash.getDHash(buffer);
  const contHash = await kkHash.getContHash(buffer)
  console.log(`contHash`,contHash)
  // eg : 0010010001100110010011000110011001001100010001000100000101100110
}

run().catch(err=>console.log(err))

and if you want to compare two picture hash:

import {kkHash,getBuffer,catchSimilarity} from 'kkhash';

const run = async()=>{
  // get buffer from local
  const buffer = await getBuffer('./**.jpg'); // or getBuffer('./**.jpg','local');
  // get buffer from internet
  const buffer2 = await getBuffer('https://www.xxx.com/xx.jpg','http');

  const aHash1 = await kkHash.getAHash(buffer1);
  const aHash2 = await kkHash.getAHash(buffer2);
  const similarity = catchSimilarity(aHash1,aHash2);
  console.log(`similarity`,similarity); // eg: 93.45
  // to use " getPHash getDHash getContHash " is like to use aHash
}

run().catch(err=>console.log(err));

you can defined "size" :

const aHash = await getAHash(someBuffer,8) // or 16 32 64

this package is created for my self in my work ... so , i will always chang or add some function , and if you installed this package,you have to remember the version you installed @.@

Readme

Keywords

Package Sidebar

Install

npm i kkhash

Weekly Downloads

1

Version

0.1.2

License

ISC

Unpacked Size

48.5 kB

Total Files

25

Last publish

Collaborators

  • kktools