Perceptual image hashing via imagemagick.
There are many ways to compute perceptual image hashes, with the open source pHash library being one of the most popular. After researching a few dozen different approaches, we've settled on imagemagick's implementation, for the following reasons:
- modern - based on an approach from 2011
- robust against a variety of attacks
- thoroughly tested
- easy to install - imagemagick has great cross-platform support
- Install a recent version of imagemagick >=
brew install imagemagickon Mac OS).
npm install --save phash-im# oryarn add phash-im
const phash =const hash1 = await phashconst hash2 = await phashconst diff = await phash
Computes the perceptual hash of the given image. Note that the result will be an array of 42 floating point values, corresponding to the 7 image moments comprised of 2 points each across 3 color channels RGB (
7 * 2 * 3 = 42).
Path to an image file.
Computes the L2 norm of the two hashes returnd by
phash.compute (sum of squared differences).
Perceptual hash of first image.
Perceptual hash of second image.
- phash-imagemagick - Alternate version of this module which parses imagemagick output instead of using json.
- pHash - A popular open source perceptual hash library.
MIT © Travis Fischer