This PHP-Script checks a Picture of a Sky and tells you how Cloudy it is. The best thing is, if you enter the Path to a Webcam Picture, which is often updated and where its Webcam is showing [ONLY] the Sky. BTW: At the Blue_Color Array you can enter the RGB-Values of a Pixel of your Sky. Its optional, but if you enter it, the Analisations will be more prectise. The Percession Variable controls which Pixels get scanned. If you have large Pictures, enter a high Number there. 62, "green" => 120, "blue" => 168); //Configuration ends .: HERE :. $image = imagecreatefrompng($image_path); $size = getimagesize($image_path); $width = $size[0]; $height = $size[1]; $words = array(0 => "The Sky is Cloudless", 5 => "The Sky is almost Cloudless", 10 => "The Sky is a little bit Cloudy", 20 => "The Sky is quite Cloudy", 30 => "There are some Clouds in the Sky", 40 => "The Sky is Cloudy", 50 => "The Sky contains many Clouds", 60 => "The Sky is very Cloudy", 70 => "The Sky is very very Cloudy", 80 => "The Sky is almost full of Clouds", 90 => "You cant even see the Sky anymore"); $cloudy = 0; $blue = colorGreyness($blue_color); unset($size); for($x = 0; $x < $width; $x += $percission) { for($y = 0; $y < $height; $y += $percission) { $cloudy += colorGreyness(getColor($image, $x, $y)) - $blue; } } $cloudy = ($cloudy / (($x * $y) / ($percission * $percission))) * 450; $output = array(); $output["Message"] = getWord($words, $cloudy); $output["Percent"] = $cloudy; function getColor($func_image, $func_x, $func_y) { $func_color = ImageColorAt($func_image, $func_x, $func_y); return ImageColorsForIndex($func_image, $func_color); } function getDifference($func_A, $func_B) { if($func_A > $func_B) return $func_A - $func_B; return $func_B - $func_A; } function colorGreyness($func_color) { $func_grey = ($func_color["red"] + $func_color["green"] + $func_color["blue"]) / 3; $func_difference = 0; $func_difference += getDifference($func_color["red"], $func_grey); $func_difference += getDifference($func_color["green"], $func_grey); $func_difference += getDifference($func_color["blue"], $func_grey); $func_greyness = (510 - $func_difference) / 510; return $func_greyness; } function getWord($func_words, $func_number) { $func_return = "No Message Found"; foreach($func_words as $func_min => $func_word) { if($func_min <= $func_number) $func_return = $func_word; } return $func_return; } ?> Cloudinator :: Result

The Sky is " . $output["Percent"] . "% Cloudy"; ?>

If you want to see the Picture of the Sky, click here.

©Copyright 2009 Alexander Rath