37 lines
920 B
PHP
Executable File
37 lines
920 B
PHP
Executable File
<?php
|
|
function isImageBright($imagePath, $sampleRate = 10) {
|
|
// Charger l'image
|
|
$image = imagecreatefrompng($imagePath);
|
|
if (!$image) return false;
|
|
|
|
$width = imagesx($image);
|
|
$height = imagesy($image);
|
|
|
|
$totalBrightness = 0;
|
|
$count = 0;
|
|
|
|
// Parcourir l'image avec un pas (échantillonnage)
|
|
for ($x = 0; $x < $width; $x += $sampleRate) {
|
|
for ($y = 0; $y < $height; $y += $sampleRate) {
|
|
$rgb = imagecolorat($image, $x, $y);
|
|
$r = ($rgb >> 16) & 0xFF;
|
|
$g = ($rgb >> 8) & 0xFF;
|
|
$b = $rgb & 0xFF;
|
|
|
|
// Formule de luminance relative
|
|
$brightness = (0.299 * $r + 0.587 * $g + 0.114 * $b);
|
|
$totalBrightness += $brightness;
|
|
$count++;
|
|
}
|
|
}
|
|
|
|
imagedestroy($image);
|
|
|
|
$averageBrightness = $totalBrightness / $count;
|
|
// echo 'averageBrightness = ' .$averageBrightness;
|
|
|
|
// Seuil : 128 est généralement un bon point de séparation
|
|
return $averageBrightness > 9;
|
|
}
|
|
?>
|