$x, 'color' => $color_str]; } } // Compact similar colors to find major blocks $blocks = []; $threshold = 5; foreach ($colors as $c) { if (empty($blocks)) { $blocks[] = $c; } else { $last = $blocks[count($blocks)-1]; if (abs(hexdec(substr($last['color'],0,2)) - hexdec(substr($c['color'],0,2))) > $threshold || abs(hexdec(substr($last['color'],2,2)) - hexdec(substr($c['color'],2,2))) > $threshold || abs(hexdec(substr($last['color'],4,2)) - hexdec(substr($c['color'],4,2))) > $threshold) { $blocks[] = $c; } } } foreach ($blocks as $i => $b) { $width = ($i < count($blocks)-1 ? $blocks[$i+1]['x'] : $w) - $b['x']; if ($width > 10) { echo "x: {$b['x']}, width: {$width}, color: #{$b['color']}\n"; } }