Skip to content

ytetsuro/image-hash

Folders and files

NameName
Last commit message
Last commit date
Apr 29, 2021
Aug 25, 2019
Aug 26, 2019
Oct 19, 2020
Oct 19, 2020
Nov 18, 2019
Aug 27, 2019
Aug 25, 2019
Oct 19, 2020
Jul 26, 2021
Jul 21, 2021
Jul 9, 2021
Oct 19, 2020

Repository files navigation

Build Status codecov

Browser image hash

This is browser image hash generator.

This library is made to generate the same hash as image-hash as much as possible.

Supported.

  • difference hashing (dHash)

Feature Suuport.

  • average hashing (aHash)
  • perception hashing (pHash)
  • wavelet hashing (wHash)

Installation

$ npm install browser-image-hash

Basic Using

import {DifferenceHashBuilder, Hash} from 'browser-image-hash';

document.addEventListener('DOMContentLoaded', async () => {
  const builder = new DifferenceHashBuilder();
  const targetURL = new URL('./example.jpg', window.location.href);
  const destHash = await builder.build(targetURL);
  const srcHash = new Hash('0111011001110000011110010101101100110011000100110101101000111000');

  if (srcHash.getHammingDistance(destHash) <= 10) {
     console.log('Resembles');
     return;
  }

  console.log('Different');
});

⚠️ Since this library uses canvas, please be careful of the same origin policy.

Allowing cross-origin use of images and canvas