API reference
This page is intentionally simple for now. Replace with generated stubs later if preferred.
ImageHashIndex
Main in-memory index.
php
$index = new ImageHashIndex();add()
Add a precomputed hash.
php
$index->add(string $id, string $hash): voidExample:
php
$index->add('image-1', 'f123456789abcdef');search()
Search by hash.
php
$index->search(string $hash, int $maxDistance = 10, int $limit = 10): arrayExample:
php
$matches = $index->search('f123456789abcdef', maxDistance: 5, limit: 20);searchImage()
Search by image.
php
$matches = $index->searchImage('exmaple.png', maxDistance: 5, limit: 20);nearest()
Find the nearest indexed match.
php
$index->nearest(string $hash): arrayExample:
php
$index->add('near', 'aaaaaaaaaaaaaaab');
$index->add('far', 'ffffffffffffffff');
$nearest = $index->nearest('aaaaaaaaaaaaaaaa');Output:
php
[
'id' => 'near'
'distance' => 2
]nearestImage()
Find the closest matching image.
php
$index->nearest(string $path): arrayExmaple:
php
$index->addImage('cat', 'cat.jpg');
$index->addImage('dog', 'dog.jpg');
$match = $index->nearestImage('cat-cropped.jpg');Output:
php
[
'id' => 'cat',
'distance' => 2
]save()
Save the index to disk.
php
$index->save(string $path): voidload()
Load a saved index.
php
$index = ImageHashIndex::load(string $path);Result shape
Expected result shape:
php
[
[
'id' => 'image-1',
'distance' => 0,
],
[
'id' => 'image-2',
'distance' => 2,
],
]stats
Show curent index statistics
php
$index->stats()php
$stats = $index->stats();
print_r($stats);Example output
php
[
'hashes' => 5000000
'buckets' => 65536
'memory_bytes' => 184320000
]| Field | Description |
|---|---|
| hashes | Total hashes stored in the index |
| buckets | Internal bucket count used for candidate pruning |
| memory_bytes | Approximate memory used by the index |