resizeExact($image, $width, $height); // Resize to exactly 9x8 $gd = $image->getCore(); // Build hash $hash = ''; for ($y = 0; $y < $height; $y++) { // Get the pixel value for the leftmost pixel. $rgba = imagecolorat($gd, 0, $y); $r = ($rgba >> 16) & 0xFF; $g = ($rgba >> 8) & 0xFF; $b = $rgba & 0xFF; $left = floor(($r + $g + $b) / 3); for ($x = 1; $x < $width; $x++) { // Get the pixel value for each pixel starting from position 1. $rgba = imagecolorat($gd, $x, $y); $r = ($rgba >> 16) & 0xFF; $g = ($rgba >> 8) & 0xFF; $b = $rgba & 0xFF; $right = floor(($r + $g + $b) / 3); // Each hash bit is set based on whether the left pixel is brighter than the right pixel. if ($left > $right) { $hash .= '1'; } else { $hash .= '0'; } // Prepare the next loop. $left = $right; } } $editor->free( $image ); return $hash; } }