> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $brightness = (int)(($r + $g + $b) / 3); $total_brightness += $brightness; } } $avg_brightness = $total_brightness / ($width * $height); // Determine if the image is more dark or light if ($avg_brightness < 128) { return 'dark'; } else { return 'light'; } }