Код: Выделить всё
$camIds = array('7117', '11695', '10290', '8750');
$final = 0;
$count = 0;
for ($index = 0; $index < count($camIds); $index++) {
$lightLevel = getLightLevel($camIds[$index]);
if ($lightLevel == 11.38) {
continue;
}
$final += $lightLevel;
$count++;
}
$final = round($final / $count, 2);
sg('lightLevel', $final);
//echo $final;
//if ($final <= 5.83 && date('H') > 14) {
// //Действия если стемнело;
//}
function getLightLevel($camId) {
$url = 'http://sat01.probkiizokna.ru/prb/getsnapshot.php?id=' . $camId . '&s=3&q=' . rand();
$im = @imagecreatefromjpeg($url);
imagefilter($im, IMG_FILTER_GRAYSCALE);
$rgb_tot = 0;
for ($y = 0; $y < 480; $y++) {
for ($x = 0; $x < 640; $x++) {
$rgb = imagecolorat($im, $x, $y);
$rgb_tot = $rgb + $rgb_tot;
}
}
$result = round($rgb_tot / 307200, 0);
$final = round($result / 1000000, 2);
return $final;
}