Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- <?php
- //........................................................
- //: Projectname: Cloudinator
- //: Description:
- //: Cloudinator is a PHP Script that analyses
- //: how cloudy the Sky is.
- //: It takes an PNG Picture and scans its Greyness.
- //: After it scanned, it takes the Message ($words)
- //: And displays it; together with the PercentNumber
- //: And a link to the Picture.
- //: Author:
- //: Alexander Rath
- //: A 13-Years old guy from Germany.
- //: Idea by:
- //: I dont really know who gave me dat idea, but it was
- //: here on php.net
- //: @PHP-Staff:
- //: Wouldn't a PHP-Forum great?
- //: Maybe you could make one on php.net ^_^
- //:
- //: ~Please let the Copyright Line stay! Thx :)
- //Configuration starts .: HERE :.
- $image_path = "Sky.png";
- $percission = 100;
- $blue_color = array("red" => 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;
- }
- ?>
- <html>
- <head>
- <title>Cloudinator :: Result</title>
- </head>
- <body>
- <font face="Tahoma">
- <small>
- <div style="width:200px;">
- <b><?php echo $output["Message"]; ?></b><br>
- <div align="right"><?php echo "<small>The Sky is " . $output["Percent"] . "% Cloudy</small>"; ?></div><br>
- If you want to see the Picture of the Sky, click <a href="<?php echo $image_path; ?>">here</a>.<br><br>
- <small><i>©Copyright 2009 <b>Alexander Rath</b></i></small>
- </div>
- </small>
- </font>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement