Download the PHP package legitphp/hash-money without Composer

On this page you can find all versions of the php package legitphp/hash-money. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hash-money

Hash Money πŸ’°

Latest Version on Packagist Tests Total Downloads PHP Version

Cache rules everything around me.

Onions? Eggs? What do you like with your hash?

Hash Money

We're serving up a performance-oriented and opinionated collection of similarity hashing algorithms for PHP. Whether you're comparing images, finding duplicates, or measuring how alike things are - we got you covered. We're riding dirty with php-vips for maximum speed. Get your FFI poppin'.

Features

Algorithms

Perceptual Hash (pHash)

DCT-based algorithm that's robust to scaling, aspect ratio changes, and minor color variations. Best for finding near-duplicate images.

Difference Hash (dHash)

Gradient-based algorithm that's faster than pHash and good at detecting similar images. It works by comparing adjacent pixels to encode the image structure.

Color Histogram Hash

Color distribution-based algorithm that captures global color patterns in images. Particularly effective for finding images with similar color palettes.

MashedHash πŸ₯”

A comprehensive image fingerprint that "mashes" together multiple image characteristics into a single 64-bit hash. This algorithm analyzes 11 different aspects of an image to create a rich signature that captures both content and style.

Bit Layout (64 bits total):

Why use MashedHash?

Gray coding note: Ordinal integer fields (colorfulness, edge density, entropy, aspect ratio, RGB channel levels, brightness, texture, dominant colors) are stored in reflected-binary Gray code so adjacent quantization levels differ by exactly one bit. Reading raw bit fields directly sees the Gray-coded representation; use MashedHash::decode($hash) to read semantic values.

Block Mean Hash

Spatial-domain fingerprint: resize the image to a √bits Γ— √bits grayscale grid, compute the mean luminance of the whole grid, then set one bit per cell based on whether that cell is brighter than the overall mean.

PDQ Hash

Industrial-scale 256-bit perceptual hash from Meta ThreatExchange. Closely related to pHash but designed for billions-scale matching:

This is an independent port of Meta's BSD-3-Clause reference. See LICENSE.md for the third-party notice.

Composite Hash

Concatenates several algorithms' 64-bit output into one wider fingerprint with independent signal types in each chunk. The default composition is the 256-bit "quartet" pHash + dHash + ColorHistogram + BlockMean:

Chunk boundaries are preserved in the HashValue's chunks metadata so LSH helpers can band each chunk separately. See the LSH helpers section below.

Requirements

Installation

You can install the package via composer:

Installing libvips

Ubuntu/Debian:

macOS:

Then install the PHP extension:

Versioning

Hash Money follows semantic versioning. Pin with "legitphp/hash-money": "^1.1" to take patch releases and additive minor releases automatically while opting in to majors deliberately.

If you're rolling out at scale (~100K+ images), also read PRE_BATCH_REVIEW.md before generating a production dataset β€” the guide covers version prerequisites, timing calibration, distribution/collision checks, and a go/no-go checklist.

Usage

Basic Usage

Configurable Hash Sizes

Smaller hash sizes are faster to compute and compare but may produce more false positives. Choose based on your needs:

Type Safety

Configure VIPS

Distance Interpretation

The Hamming distance between two hashes indicates how similar the images are.

Advanced Usage

Working with Hash Values

The HashValue class provides a rich API for working with hash results:

Batch Processing

Performance Optimization

Enhanced HashValue Features

The HashValue class includes advanced features for flexible hash manipulation and storage:

Factory Methods and Serialization

Create HashValue objects from various formats:

Metadata Support

Attach metadata to hash values for richer data management:

Bitwise Analysis

Examine hash properties at the bit level:

Advanced Comparisons

Built-in methods for sophisticated hash comparison:

Scaling to Large Datasets (LSH + MIH)

Once you have millions of hashes in a database, naΓ―ve BIT_COUNT(a ^ b) <= k scans become prohibitively slow. Two helpers are provided for building indexed similarity search:

Multi-Index Hashing (MIH) β€” best for 64-bit hashes, small thresholds

For Hamming threshold k bits on a 64-bit hash, split the hash into m > k equal chunks. Pigeonhole: any two hashes within k bits must have at least one chunk matching exactly. Index each chunk as its own BIGINT column and query with m equality lookups, union the results, then verify the full Hamming distance on the small candidate set:

MIH is typically 2–3 orders of magnitude faster than full-table BIT_COUNT scans for k ≀ 8 on 64-bit hashes. For larger thresholds or wider hashes, use LSH banding instead.

LSH Banding β€” best for composite / wider hashes

For a wide hash, split into B bands of R bits each. Each band's bytes become a bucket key; two hashes are "candidates" when they share any bucket key. Lsh::bandsByChunk() is composite-aware β€” it sub-bands each semantic chunk independently so candidates are "matched on at least one of structure, edges, color, or layout":

Tune bands vs. chunks against your dataset β€” more bands raises recall but inflates the candidate set. A reasonable starting point for a 256-bit composite is 16 bands (B=16, R=16 β†’ 65,536 buckets per band).

Candidate-filtering is usually done in the database; see docs/LARAVEL_BRIDGE.md for a proposed Laravel package that wires all of this (Eloquent cast, migrations, scopes, pluggable MySQL-chunked / MySQL-banded drivers) on top of this library.

Real-World Examples

Database Storage Pattern

Store and retrieve hashes efficiently:

API Integration

Send and receive hashes via APIs:

Duplicate Detection System

Build a complete duplicate detection workflow:

Example Scripts and Benchmarks

Hash Generation Example

The package includes a comprehensive example script for testing hash generation:

Testing

Run the test suite using Pest:

For code formatting:

Performance Considerations

Rolling Out at Scale

Before generating hashes for a large production dataset (~100K images or more), run the calibration and validation steps in PRE_BATCH_REVIEW.md inside your consumer project. The guide covers version prerequisites, timing extrapolation, hash-distribution sanity checks, known-pair validation, failure-mode probes, database/query-plan review, and a go/no-go checklist. It's intended to be executable by either a human operator or an AI coding agent working in the consumer repo, and produces a single report that justifies the decision to run the full batch.

Use Cases

Choosing the Right Hash

Hash Type Best For Speed Key Features
pHash Near-duplicate detection, scaled/compressed variants Medium Robust to compression, scaling, minor edits
dHash Quick similarity checks, cropped images Fast Good for crops, sensitive to rotation
ColorHistogram Color-based matching, filter detection Fast Catches recolored/filtered versions
MashedHash Reducing false positives (as augmenting signal) Medium 11 Gray-coded features, read via decode()
BlockMean Spatial layout fingerprint Fast Orthogonal to pHash/dHash, 8/16/…/256-bit
PDQ Large-scale near-duplicate detection (256-bit) Slower 256-bit, gradient-based quality metric, 8 dihedral variants
Composite LSH-friendly multi-view fingerprint Medium Chunks carry independent signal types

Recommended Combinations

For social media images:

For copyright detection:

For large-scale similarity search with LSH:

For industrial-scale near-duplicate detection with PDQ:

PDQ produces a 256-bit HashValue directly β€” no getValue()-style int accessor; use toHex(), getBytes(), or toBase64() for storage. Wide LSH banding works exactly like for CompositeHash outputs: pass the HashValue to Lsh::bands($hash, $bandCount).

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

Acknowledgments

Special thanks to the authors and contributors of the libraries that made this package possible, particularly the VIPS team for their incredible image processing library.


All versions of hash-money with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
jcupitt/vips Version ^2.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package legitphp/hash-money contains the following files

Loading the files please wait ...