$ show pwlmc/imghash
imghash is a Node.js library for computing perceptual image hashes (pHash) using the block mean value based hashing method. It supports PNG, JPEG, BMP, and WebP image formats, and can accept file paths or Buffers as input. The library provides a simple async API to generate hashes in hex or binary format, with configurable bit lengths. It includes utility functions for converting between hex and binary representations. The codebase is written in TypeScript, well-tested with unit and e2e tests, and follows modern JavaScript practices. It handles edge cases such as palette-based PNGs and problematic JPEG images that cause longjmp errors in WebAssembly decoders by falling back to an alternative JPEG library.
The LLM identified 1 files worth highlighting for reuse:
The main module implementing the perceptual hash computation. It provides an async hash function that reads image files or Buffers, decodes them using @canvas/image with a fallback to jpeg-js for problematic JPEGs, and computes the block mean value hash via blockhash-core. The module also exports utility functions hexToBinary and binaryToHex for hash format conversion. The code demonstrates clean error handling, async/await usage, and a robust fallback pattern for handling edge cases in image decoding.