A blazing-fast TypeScript library that creates visual fingerprints of images. Find duplicates, detect similar images, and organize collections with precision.
Built with performance and simplicity in mind. No external dependencies, works everywhere JavaScript runs.
Optimized DCT (Discrete Cosine Transform) implementation delivers hashes in milliseconds, even for large images.
Works seamlessly in browsers and Node.js. Built with TypeScript for type safety and excellent developer experience.
No external packages required. Lightweight bundle size means faster load times and reduced security surface.
Unlike cryptographic hashes, perceptual hashes produce similar outputs for visually similar images.
The image is resized to a small sample (default 64x64) and converted to grayscale, removing color information while preserving structure.
A Discrete Cosine Transform extracts frequency information, focusing on the low-frequency components that represent the image's overall structure.
The top-left 8x8 DCT values are compared against the median to produce a 64-bit binary hash, represented as a hexadecimal string.
Similar images have hashes with few bit differences. A Hamming distance of 10 or less typically indicates the same or very similar images.
Explore the library capabilities with these interactive demos. No installation required.
Upload an image and instantly compute its perceptual hash. Watch the algorithm process and visualize the result.
Upload two images and see how similar they are. Get detailed similarity scores and Hamming distance.
Process multiple images at once. Find duplicates and similar images in your collection automatically.
Get started in seconds with our intuitive API.
// 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)}%`);