note 88954 added to function.imagecolorat

From: Date: Sun, 15 Feb 2009 07:36:25 +0000
Subject: note 88954 added to function.imagecolorat
Groups: php.notes 
Request: Send a blank email to php-notes+get-150694@lists.php.net to get a copy of this message
With this example you can calculate the weather status :) Just put an image (webcam) in an img folder, and run this script. <?php $img = "img/clouds.gif"; $imgHand = ImageCreateFromGIF; $imgSize = GetImageSize($img); $imgWidth = $imgSize[0]; $imgHeight = $imgSize[1]; echo '<img src="'.$img.'"><br><br>'; for ($l = 0; $l < $imgHeight; $l++) { for ($c = 0; $c < $imgWidth; $c++) { $pxlCor = ImageColorAt($imgHand,$c,$l); $pxlCorArr = ImageColorsForIndex($imgHand, $pxlCor); $htmlCor = DecHex($pxlCorArr["red"]&240) . DecHex($pxlCorArr["red"]&240) . DecHex($pxlCorArr["red"]&240); $grey[convert($htmlCor)/16]++; } } for ($i=0;$i<16;$i++){ echo 'greyvalue '.$i.' : '.$grey[$i].'<br>'; } echo '<br><br>Status: <b>'.status(count($grey)).'</b><br>'; function convert($color){ $hexdec=HexDec($color)&240; $decbin=DecBin($hexdec); $decbin = substr("00000000",0,8 - strlen($decbin)) . $decbin; $bindec = BinDec($decbin); return $bindec; } function status($range){ if ($range >= 13) return "Heavy Clouds"; elseif ($range > 9 && $range < 13) return "Cloudy"; elseif ($range > 4 && $range <=9) return "Light cloudy"; elseif ($range <= 4) return "Clear"; } ?> ---- Server IP: 195.207.10.20 Probable Submitter: 91.178.125.200 ---- Manual Page -- http://www.php.net/manual/en/function.imagecolorat.php Edit -- https://master.php.net/note/edit/88954 Del: integrated -- https://master.php.net/note/delete/88954/integrated Del: useless -- https://master.php.net/note/delete/88954/useless Del: bad code -- https://master.php.net/note/delete/88954/bad+code Del: spam -- https://master.php.net/note/delete/88954/spam Del: non-english -- https://master.php.net/note/delete/88954/non-english Del: in docs -- https://master.php.net/note/delete/88954/in+docs Del: other reasons-- https://master.php.net/note/delete/88954 Reject -- https://master.php.net/note/reject/88954 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150694) next »