a4b3c2d1e5f6
f7e8d9c0b1a2
1234abcd5678
dead beef cafe
9876543210ab
ffee ddcc bbaa
Zero Dependencies. Browser & Node.js Ready

Perceptual Image
Hashing Made Simple

A blazing-fast TypeScript library that creates visual fingerprints of images. Find duplicates, detect similar images, and organize collections with precision.

Everything you need for
image fingerprinting

Built with performance and simplicity in mind. No external dependencies, works everywhere JavaScript runs.

Lightning Fast

Optimized DCT (Discrete Cosine Transform) implementation delivers hashes in milliseconds, even for large images.

DCT Algorithm Async Processing Batch Support

Universal Runtime

Works seamlessly in browsers and Node.js. Built with TypeScript for type safety and excellent developer experience.

Browser Node.js TypeScript

Zero Dependencies

No external packages required. Lightweight bundle size means faster load times and reduced security surface.

Minimal Footprint Self-Contained Secure

Understanding
Perceptual Hashing

Unlike cryptographic hashes, perceptual hashes produce similar outputs for visually similar images.

1

Resize & Convert

The image is resized to a small sample (default 64x64) and converted to grayscale, removing color information while preserving structure.

2

Apply DCT Transform

A Discrete Cosine Transform extracts frequency information, focusing on the low-frequency components that represent the image's overall structure.

3

Generate Hash

The top-left 8x8 DCT values are compared against the median to produce a 64-bit binary hash, represented as a hexadecimal string.

4

Compare with Hamming Distance

Similar images have hashes with few bit differences. A Hamming distance of 10 or less typically indicates the same or very similar images.

Try it yourself

Explore the library capabilities with these interactive demos. No installation required.

Single Image Hash

Upload an image and instantly compute its perceptual hash. Watch the algorithm process and visualize the result.

Drag & Drop Hash Visualization Custom Options
Try it now

Compare Images

Upload two images and see how similar they are. Get detailed similarity scores and Hamming distance.

Side-by-Side Similarity Score Visual Diff
Try it now

Batch Processing

Process multiple images at once. Find duplicates and similar images in your collection automatically.

Multiple Files Duplicate Detection Export Results
Try it now

Simple API, Powerful Results

Get started in seconds with our intuitive API.

example.ts
// Install the package
// npm install @stabilityprotocol.com/phash

import { fromFile, hammingDistance } from '@stabilityprotocol.com/phash';

// Generate hash from a file
const hash1 = await fromFile(imageFile);
const hash2 = await fromFile(anotherFile);

// Compare similarity
const distance = hammingDistance(hash1, hash2);
const similarity = 100 - (distance / 64 * 100);

console.log(`Similarity: ${similarity.toFixed(1)}%`);