monolith-phash-algo
v0.1.0
Published
Perceptual hash (pHash) implementation for Node and browser.
Downloads
154
Readme
monolith-phash-algo
Perceptual hash (pHash) implementation that runs in Node and the browser with no dependencies.
Install
npm install monolith-phash-algoUsage
ESM (browser or Node):
import phash, { fromRgba, fromImageData, fromImage, fromFile } from "monolith-phash-algo";
const hash = fromRgba(rgba, width, height);
const hashFromImageData = fromImageData(imageData);
const hashFromImage = fromImage(imgElement);
const hashFromFile = await fromFile(file);
const hashViaDefault = phash(rgba, width, height);CommonJS (Node):
const phash = require("monolith-phash-algo");
const hash = phash.fromRgba(rgba, width, height);API
phash(input, width?, height?, options?)- Accepts ImageData-like objects, or RGBA buffers with width and height.
fromRgba(rgba, width, height, options?)fromImageData(imageData, options?)fromImage(image, options?)(browser-only unless you provide a canvas implementation)fromFile(file, options?)(browser-only)algorithms.universal.*access to the current algorithm implementation.
Options
hashSize(default: 8)sampleSize(default: 64)createCanvas(width, height)custom canvas factory for environments without DOM or OffscreenCanvas.
