# imghash **Repository Path**: mirrors_floatdrop/imghash ## Basic Information - **Project Name**: imghash - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-24 - **Last Updated**: 2026-05-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # imghash [![Build Status](https://secure.travis-ci.org/pwlmaciejewski/imghash.png?branch=master)](http://travis-ci.org/pwlmaciejewski/imghash) Promise-based image perceptual hash calculation for node. ## Installation ``` npm install imghash ``` ## Basic usage ```javascript const imghash = require('imghash'); imghash .hash('path/to/file') .then((hash) => { console.log(hash); // 'f884c4d8d1193c07' }); // Custom hex length and result in binary imghash .hash('path/to/file', 4, 'binary') .then((hash) => { console.log(hash); // '1000100010000010' }); ``` ## Finding similar images To measure similarity between images you can use [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) or [Levenshtein Distance](https://en.wikipedia.org/wiki/Levenshtein_distance). Here's an example of using the first one: ```javascript const imghash = require('imghash'); const hamming = require('hamming-distance'); const hash1 = imghash.hash('./img1'); const hash2 = imghash.hash('./img2'); Promise .all([hash1, hash2]) .then((results) => { const dist = hamming(results[0], results[1]); console.log(`Distance between images is: ${dist}`); if (dist <= 20) { console.log('Images are similar'); } else { console.log('Images are NOT similar'); } }); ``` ## 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 are `png` and `jpeg`) or `Buffer` * `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` takes advantage of block mean value based hashing method: * [http://stackoverflow.com/questions/14377854/block-mean-value-hashing-method](http://stackoverflow.com/questions/14377854/block-mean-value-hashing-method) * [http://commonsmachinery.se/2014/09/digital-image-matching-part-1-hashing/](http://commonsmachinery.se/2014/09/digital-image-matching-part-1-hashing/)