Encode Command
The hazehash command comes with the hazehash package. It needs the optional package sharp to read images:
npm install --save-dev hazehash sharp
npx hazehash --helpEvery command has its own --help with the full list of options. The global options are -h, --help, -V, --version and --color / --no-color. Colours are also off when the output is piped, when NO_COLOR is set and on a dumb terminal, and FORCE_COLOR turns them on. The other commands are on Decode and Info Commands.
encode
Creates hashes from image files, folders, globs or standard input. In a terminal the result is a coloured table with the size of each image, the size of its hash, the average colour and a summary; when the output is piped it is plain text, so scripts can use it as it is.
hazehash encode <input…> [options]An input is an image file, a folder, a glob such as "photos/**/*.jpg" (quote it so your shell does not expand it) or - to read one image from standard input.
Example — one image, printed alone:
hazehash encode photo.jpgEd7UwRWKKv5znm6a7sC1tziHDNpMuCikxrYpIgExample — a folder, as a table:
hazehash encode ./images --prettyHazeHash encode budget 28 B · profile default · alpha auto
Image Pixels File Hash Value
✔ images/alpha-003.png 1280×510 43.4 KB 13 B NYATKSAAADXSSaWLiA
✔ images/city-012.jpg 1280×959 280.6 KB 28 B Ed7UwRWKKv5znm6a7sC1tziHDNpMuCikxrYpIg
✔ images/document-004.jpg 1280×821 508.7 KB 28 B Et4TPyOAQNXnVbzFulUm5bq7tUi1isKm3pOziQ
✔ 3 hashes · 832.8 KB → 69 B · 12,359× smaller · 186 msThe table above is the layout for 100 columns. A wider terminal also shows the average colour of each image, with a colour swatch, and how many times the hash is smaller than the file; a narrower one drops the less important columns first.
Hash options
-b, --budget <bytes>
The maximum size of one hash in bytes, header included. Default 28; the minimum is 7 bytes, or 9 with alpha. More bytes keep more detail; see Choosing a budget.
hazehash encode photo.jpg --budget 24-p, --profile <name>
How hard the encoder searches: fast (about 1 ms per image), default (about 5 ms) or high (refines the result for about 1% less error). Default default.
-a, --analysis-size <px>
The long side of the downscaled image the hash is computed from, 32–128. Default 64; larger rarely helps.
--alpha <mode>
auto stores transparency only when the image has some (the default), true always stores it, and false never does.
Which images
-r, --recursive
Also search sub-folders when an input is a folder. A glob with ** always does.
Output
-f, --format <kind>
text writes the hash alone for one image, or path<TAB>hash lines for several. json writes an object { "path": "hash" }. csv writes a table with a header row. Default text.
hazehash encode ./images -f json{
"images/alpha-003.png": "NYATKSAAADXSSaWLiA",
"images/city-012.jpg": "Ed7UwRWKKv5znm6a7sC1tziHDNpMuCikxrYpIg",
"images/document-004.jpg": "Et4TPyOAQNXnVbzFulUm5bq7tUi1isKm3pOziQ"
}--details
With json and csv, adds the size of the hash, the size of the image and the size of the file.
hazehash encode ./images -f csv --detailsfile,hash,bytes,width,height,fileBytes
images/alpha-003.png,NYATKSAAADXSSaWLiA,13,1280,510,44406
images/city-012.jpg,Ed7UwRWKKv5znm6a7sC1tziHDNpMuCikxrYpIg,28,1280,959,287378
images/document-004.jpg,Et4TPyOAQNXnVbzFulUm5bq7tUi1isKm3pOziQ,28,1280,821,520957--hex
Writes hashes as hex instead of base64url.
hazehash encode photo.jpg --hex
# 11ded4c1158a2afe739e6e9aeec0b5b738870cda4cb828a4c6b62922-o, --output <file>
Writes the result to a file instead of standard output.
hazehash encode "images/**/*.jpg" -f json -o hashes.json--pretty, --plain
--pretty is the coloured table with a summary, the default in a terminal. --plain is for scripts and the default when the output is piped.
-q, --quiet
No progress and no summary, only the result and the errors.
Reading from standard input
cat photo.jpg | hazehash encode -Exit codes
0— every image was encoded.1— at least one input failed. The others are still written, and the failure is reported on standard error.2— a mistake in the command line.
An input that is not found is reported like this:
✖ nothing.jpg: no image found