Color Analysis & Perceptual Hashing
InterventionImage ships two visual intelligence engines built directly onto Pageimage, both cached in JSON sidecars alongside the original file so repeated template renders incur zero image decoding cost.
1. Visual Color Extraction ({basename}.colors.json)
Section titled “1. Visual Color Extraction ({basename}.colors.json)”<?php namespace ProcessWire;
/** @var Pageimage $image */
// Dominant hex color (pass true for hex string)$dominant = $image->dominantColor(true); // '#1e293b'
// N-color palette array$palette = $image->palette(6, true); // ['#1e293b', '#38bdf8', ...]
// 6-token semantic theme map$theme = $image->colorTheme(true);// [// 'vibrant' => '#0284c7',// 'muted' => '#64748b',// 'darkVibrant' => '#0369a1',// 'darkMuted' => '#1e293b',// 'lightVibrant' => '#7dd3fc',// 'lightMuted' => '#cbd5e1',// ]2. Perceptual Hashing & Duplicate Detection ({basename}.hashes.json)
Section titled “2. Perceptual Hashing & Duplicate Detection ({basename}.hashes.json)”Fingerprint any Pageimage using four perceptual algorithms via Intervention\ImageHash:
| Strategy | Bit Length | Hex Length | Best For |
|---|---|---|---|
'dhash' (default) |
64-bit | 16 hex chars | Fast near-duplicate detection across resizes and JPEG/WebP re-encoding |
'phash' |
64-bit | 16 hex chars | Robust perceptual matching under minor cropping or gamma changes |
'ahash' |
64-bit | 16 hex chars | Ultra-fast average luminance comparison |
'bhash' |
256-bit | 64 hex chars | High-precision block-mean fingerprinting |
$hash = $image->imageHash('dhash');$distance = $image->hashDistance($otherImageOrHex, 'dhash'); // Hamming distance (0 = identical)$isDuplicate = $image->isSimilar($otherImageOrHex, 5, 'dhash'); // true when distance <= 5Managing Sidecar Caches
Section titled “Managing Sidecar Caches”Purge color or hash sidecars independently via PHP or CLI without touching your generated WebP/AVIF variations:
php vendor/bin/wire image:clear --colors-only --dry-run --jsonphp vendor/bin/wire image:clear --hashes-only --force --json