imghash-turbo
Promise-based image perceptual hash calculation for node, with support for jpg-turbo. A fork of 'imghash'
Pre Requisites
You must have the packages specified in the jpeg-turbo docs installed to be able to build. https://github.com/sorccu/node-jpeg-turbo
Installation
npm install imghash-turbo
Basic usage
const imghash = ; imghash hash'path/to/file' ; // Custom hex length and result in binaryimghash hash'path/to/file' 4 'binary' ;
Finding similar images
To measure similarity between images you can use Hamming distance or Levenshtein Distance. Here's an example of using the first one:
const imghash = ;const hamming = ; const hash1 = imghashhash'./img1';const hash2 = imghashhash'./img2'; Promise allhash1 hash2 ;
API
.hash(filepath[, bits][, format])
Returns: ES6 Promise
, resolved returns hash string in specified format and length (eg. f884c4d8d1193c07
)
Parameters:
filepath
- path to the image (supported formats arepng
andjpeg
) orBuffer
bits
(optional) - hash length [default:8
]format
(optional) - output format [default:hex
]
===
.hashRaw(data, bits)
Returns: hex hash
Parameters:
data
- image data descriptor in form{ width: [width], height: [height], data: [decoded image pixels] }
bits
- hash length
===
.hexToBinary(s)
Returns: hex string, eg. f884c4d8d1193c07
.
Parameters:
s
- binary hash string eg.1000100010000010
===
.binaryToHex(s)
Returns: hex string, eg. 1000100010000010
.
Parameters:
s
- hex hash string eg.f884c4d8d1193c07
Further reading
imghash-turbo
takes advantage of block mean value based hashing method: