# # # # $autoScale = true; enables autoranging on output scale. The program will # # add majortick values to maximum or substract majortick values from minimum # # to always show the scale, current, minimum, maximum on the graphic. # ################################################################################ # This program is free software; you can redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the Free # # Software Foundation; either version 2 of the License, or (at your option) # # any later version. # # # # This program is distributed in the hope that it will be useful, but # # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # # or FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License along with # # this program; if not, write to the: # # Free Software Foundation, Inc., # # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA # ################################################################################ # VERSION HISTORY: # # --- Version 1.00 - 17-Sep-2007 - Initial release. # # --- Version 1.01 - 18-Nov-2007 - added GD test, autoscale function, updated # # for sce=view on IIS systems. # # --- Version 1.02 - 23-Nov-2007 - fixed Notice: errata on min/max calculations# # --- Version 1.03 - 28-Feb-2008 - added support for Carterlake/AJAX/PHP # # template integration. # ################################################################################ # BASHEWA.COM VERSION HISTORY: (by Rainer Finkeldeh) # # --- Version 1.04 - 05-Jan-2010 - added gradient thermometer # # --- Version 1.05 - 06-Jan-2010 - added transparent thermometer # # --- Version 1.06 - 06-Jan-2010 - added old transparent thermometer # # --- Version 1.07 - 06-Jan-2010 - added tick colors # # --- Versiom 1.08 - 09-Jan-2010 - re-added show current temperature on bulb. # # added option to show UOM on bulb. # ################################################################################ # This document uses Tab 3 Settings # ################################################################################ //--self downloader -- if (isset($_REQUEST['sce']) && ( strtolower($_REQUEST['sce']) == 'view' or strtolower($_REQUEST['sce']) == 'show') ) { $filenameReal = __FILE__; $download_size = filesize($filenameReal); header('Pragma: public'); header('Cache-Control: private'); header('Cache-Control: no-cache, must-revalidate'); header("Content-type: text/plain"); header("Accept-Ranges: bytes"); header("Content-Length: $download_size"); header('Connection: close'); readfile($filenameReal); exit; } //----------------------------------------------------------------------------\\ // SETTINGS: (required) \\ //----------------------------------------------------------------------------\\ $UOM = 'C'; // set to 'C' for Celsius/Centigrade, 'F'=Fahrenheit $wxSoftware = 'WD'; // set to 'VWS' to use VWS WeatherFlash files $autoScale = true; // set to false to disable autoscale. $showTempOnBulb = false; // show current temperature on bulb $showUOMonBulb = false; // show UOM on bulb (overrrides $showTempOnBulb) // relative file address for thermometer blank image PNG $BlankGraphic = './thermometer-blank2.png'; // blank0=red, blank1=blue, blank2=gradient, blank3=old style // You only have to set one of the below correctly based on the $wxSoftware selection // $wxSoftware = 'WD' : set the $clientrawfile // $wxSoftware = 'VWS': set the $wflashDir $clientrawfile = './clientraw.txt'; // relative file address for WD clientraw.txt $wflashDir = './wflash/Data/'; // directory for the the VWS wflash.txt and wflash2.txt files // ... relative to directory location of this script (include // ... trailing '/' in the specification //----------------------------------------------------------------------------\\ // SETTINGS: (optional) \\ //----------------------------------------------------------------------------\\ // settings for ranges -- adjust for your climate :-) // Fahrenheit settings ... keep range from low to high at 80°F $TmaxF = 100; // maximum °F temperature on thermometer $TminF = 20; // minimum °F temperature on thermometer $TincrF = 5; // increment number of degrees °F for major/minor ticks on thermometer $TMajTickF = 10; // major tick with value when °F scale number divisible by this // Centigrade settings ... keep range from low to high at 50°C $TmaxC = 40; // maximum °C temperature on thermometer $TminC = -10; // minimum °C temperature on thermometer $TincrC = 2; // increment number of degrees °C for major/minor ticks on thermometer $TMajTickC = 10; // major tick with value when °C scale number divisible by this // TICK COLORS : // ----------------- // black #000000 // white #FFFFFF // red #FF0000 // green #008000 // blue #0000FF // yellow #FFFF00 // fuchsia #FF00FF // orange #FFA500 // lightgrey #D3D3D3 // darkgrey #A9A9A9 // dimgray #696969 // ----------------- $tickColor = '#000000'; // color for tick marks and UOM $tickMaxColor = '#FF0000'; // color for max temp text $tickMinColor = '#0000FF'; // color for min temp text // ----------------------------------------------------------------------------- // I M P O R T A N T . // DO NOT customize the stuff below this point. . // Everything is controlled by your settings above. . // ----------------------------------------------------------------------------- if (!function_exists("gd_info")) die("Sorry.. this script requires the GD library in PHP to function."); if (isset($_GET["col" ])) $BlankGraphic = './thermometer-blank'.$_GET["col"].'.png'; if (isset($_GET["suob"])) $showUOMonBulb = true; if (isset($_GET["stob"])) $showTempOnBulb = true; // overrides from Settings.php if available if(file_exists("Settings.php")) { include_once("Settings.php"); } global $SITE; if (isset($SITE['uomTemp']) && !isset($_GET["uom"])) $UOM = preg_replace('|°|is','',$SITE['uomTemp']); if (isset($_GET["uom" ]) && !empty($_GET["uom"])) $UOM = ($_GET["uom"]=='M')? "C" : "F"; if ($UOM <> 'F' and $UOM <> 'C') $UOM = 'F'; if (isset($SITE['clientrawfile']) ) $clientrawfile = $SITE['clientrawfile']; if (isset($SITE['wflashdir'] ) ) $wflashDir = $SITE['wflashdir']; // end of overrides from Settings.php if (isset($_REQUEST['sw'] ) and strtolower($_REQUEST['sw'] ) == 'wd' ) { $wxSoftware = 'WD'; } // testing if (isset($_REQUEST['sw'] ) and strtolower($_REQUEST['sw'] ) == 'vws') { $wxSoftware = 'VWS'; } // testing if (isset($_REQUEST['uom']) and strtolower($_REQUEST['uom']) == 'c') { $UOM = 'C'; } if (isset($_REQUEST['uom']) and strtolower($_REQUEST['uom']) == 'f') { $UOM = 'F'; } if ($UOM == 'F') { // use Fahrenheit settings $Tmax = $TmaxF; // maximum temperature on thermometer $Tmin = $TminF; // minimum temperature on thermometer $Tincr = $TincrF; // increment number of degrees for major/minor ticks on thermometer $TMajTick = $TMajTickF; // major tick with value when scale number divisible by this } else { // use Centigrade settings $Tmax = $TmaxC; // maximum temperature on thermometer $Tmin = $TminC; // minimum temperature on thermometer $Tincr = $TincrC; // increment number of degrees for major/minor ticks on thermometer $TMajTick = $TMajTickC; // major tick with value when scale number divisible by this } // Get the Weather-Display clientraw.txt data file if ($wxSoftware == 'WD') { $dataraw = file_get_contents($clientrawfile); // clean up any blank lines $dataraw = trim($dataraw); $dataraw = preg_replace("/[\r\n]+[\s\t]*[\r\n]+/","\n",$dataraw); $data = explode(" ", $dataraw); $curtemp = CtoF($data[4],1); $mintemp = CtoF($data[47],1); $maxtemp = CtoF($data[46],1); } // end Weather display data else // Get the VWS Weather Flash data files if ($wxSoftware == 'VWS') { $filename = "${wflashDir}wflash.txt"; $file = file($filename); $file = implode('',$file); $data = explode(",",$file);; $curtemp = FtoC($data[9],1); $filename = "${wflashDir}wflash2.txt"; $file = file($filename); $file = implode('',$file); $data = explode(",",$file);; $mintemp = FtoC($data[92],1); $maxtemp = FtoC($data[36],1); } // end VWS display data if (isset($_REQUEST['current'])) $curtemp = $_REQUEST['current']; // for testing if (isset($_REQUEST['min' ])) $mintemp = $_REQUEST['min']; // for testing if (isset($_REQUEST['max' ])) $maxtemp = $_REQUEST['max']; // for testing if ($autoScale) autoscale($curtemp,$mintemp,$maxtemp); genThermometer($curtemp, $mintemp,$maxtemp); // make graphic! return; //----------------------------------------------------------------------------\\ // FUNCTIONS \\ //----------------------------------------------------------------------------\\ function genThermometer( $current,$min,$max ) { global $UOM,$BlankGraphic,$wxSoftware; global $Tmax,$Tmin,$Tincr,$TMajTick,$tickColor,$tickMinColor,$tickMaxColor,$showTempOnBulb,$showUOMonBulb; // draw a filled thermometer with scale, min max on a blank thermometer image $image = LoadPNG($BlankGraphic); // Settings relative to the thermometer image file defines the drawing area // for the thermometer filling. // These settings are SPECIFICALLY for the thermometer-blank?.png image background. $minX = 18; // left $maxX = 27; // right $minY = 20; // top $maxY = 140; // bottom $width = imagesx($image); $height = imagesy($image); $font = 1; $bg = imagecolorallocate($image,255,255,255 ); // white $tx = imagecolorallocate($image, hexdec('0x'.$tickColor{1}.$tickColor{2}) , hexdec('0x'.$tickColor{3}.$tickColor{4}) , hexdec('0x'.$tickColor{5}.$tickColor{6})); $blue = imagecolorallocate($image, hexdec('0x'.$tickMinColor{1}.$tickMinColor{2}) , hexdec('0x'.$tickMinColor{3}.$tickMinColor{4}) , hexdec('0x'.$tickMinColor{5}.$tickMinColor{6})); $red = imagecolorallocate($image, hexdec('0x'.$tickMaxColor{1}.$tickMaxColor{2}) , hexdec('0x'.$tickMaxColor{3}.$tickMaxColor{4}) , hexdec('0x'.$tickMaxColor{5}.$tickMaxColor{6})); $gray1 = imagecolorallocate($image, 38, 38, 38); $gray2 = imagecolorallocate($image, 50, 50, 50); $gray3 = imagecolorallocate($image, 97, 97, 97); $gray4 = imagecolorallocate($image,144,144,144); $gray5 = imagecolorallocate($image,191,191,191); $gray6 = imagecolorallocate($image,238,238,238); $Trange = $Tmax - $Tmin; // total temperature range $Tpct = ( $current-$Tmin ) / $Trange; // percent for current temperature of range $Y = (1-$Tpct) * ($maxY-$minY) + ($minY-1); // lower location for fill (i.e. current temp) // fill the thermometer with a gray bar from top to current temp ($Y) imagefilledrectangle ( $image ,$minX ,$minY ,$maxX ,$Y ,$bg ); imagefilledrectangle ( $image ,$maxX+1 ,$minY ,$maxX+1 ,$Y ,$gray1); imagefilledrectangle ( $image ,$maxX ,$minY ,$maxX ,$Y ,$gray2); imagefilledrectangle ( $image ,$maxX-1 ,$minY ,$maxX-1 ,$Y ,$gray3); imagefilledrectangle ( $image ,$maxX-2 ,$minY ,$maxX-2 ,$Y ,$gray4); imagefilledrectangle ( $image ,$maxX-3 ,$minY ,$maxX-3 ,$Y ,$gray5); imagefilledrectangle ( $image ,$maxX-4 ,$minY ,$maxX-4 ,$Y ,$gray6); // Draw tick marks and scale values on right for ($T=$Tmin;$T<=$Tmax;$T+=$Tincr) { $Tpct = ( $T-$Tmin ) / $Trange; $Y = ( 1-$Tpct ) * ( $maxY-$minY ) + $minY; if ($T == 0 or ($T % $TMajTick) == 0) { // Major Tick imagefilledrectangle( $image ,$maxX+4 ,$Y ,$maxX+9 ,$Y+1 ,$tx ); imagestring($image, $font ,$maxX+11 ,$Y - (ImageFontHeight($font)/2) ,sprintf( "%2d", $T),$tx); } else { // Minor tick imagefilledrectangle( $image ,$maxX+4 ,$Y ,$maxX+6 ,$Y+1 ,$tx ); } } // end do ticks legend // Put on minimum temp bar/value if(isset($min)) { $Tpct = ( $min-$Tmin ) / $Trange ; $Y = ( 1-$Tpct ) * ( $maxY-$minY ) + $minY; imagefilledrectangle( $image ,$minX-18 ,$Y ,$minX - 5 ,$Y+1, $blue ); $tstr = sprintf('%2d',round($min,0)); $tsize = strlen($tstr) * imagefontwidth($font+1); imagestring( $image, $font+1 ,$minX-$tsize-3 ,$Y+2 ,$tstr ,$blue ); } // Put on maximum temp bar/value if(isset($max)) { $Tpct = ( $max-$Tmin ) / $Trange; $Y = ( 1-$Tpct ) * ( $maxY-$minY ) + $minY; imagefilledrectangle( $image ,$minX-18 ,$Y ,$minX-5 ,$Y+1, $red ); $tstr = sprintf('%2d',round($max,0)); $tsize = strlen($tstr)*imagefontwidth($font+1); imagestring($image, $font+1 ,$minX-$tsize-3 ,$Y-imagefontheight($font+1) ,$tstr ,$red ); } // Put UOM legend on top or on bulb $cnt = '°' . $UOM; $tsize = strlen($cnt)*imagefontwidth($font+2); if ($showUOMonBulb) { $X = (($minX+$maxX)/2) - ($tsize/2)+1; $Y = $maxY+6; $color = $bg; } else { $X = ($width/2) - ((strlen($cnt)/2) * ImageFontWidth($font+2) + 4); $Y = (10 - ( ImageFontHeight($font+2) / 2 ) - 1); $color = $tx; } imagestring ($image ,$font+2 ,$X ,$Y ,$cnt ,$color); // Write current temperature on thermometer bulb if ($showTempOnBulb && !$showUOMonBulb) { $tstr = sprintf('%2d',round($current,0)); $tsize = strlen($cnt)*imagefontwidth($font); imagestring($image, $font, (($minX+$maxX)/2) - ($tsize/2)+1 ,$maxY+8, $tstr ,$bg); } // Send the image header("content-type: image/png"); imagepng($image); imagedestroy($image); } // end genThermometer // load PNG image function LoadPNG ($imgname) { $im = @imagecreatefrompng ($imgname); /* Attempt to open */ if (!$im) { /* to see if it failed */ $im = imagecreate (150, 30); /* Create a blank image */ $bgc = imagecolorallocate ($im, 255, 255, 255); $tc = imagecolorallocate ($im, 0, 0, 0); imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc); } imageAlphaBlending($im, false); imageSaveAlpha($im, true); return $im; } // CtoF: converts degrees Celcius to degress Farenheight (from Anolecomputing.com) function CtoF($value, $precision) { global $UOM; if ($UOM <> 'F') { return round($value,$precision); } else { return round($value = (($value * 9 / 5) + 32),$precision); } } // end function C_to_F // FtoC: converts degress Farenheight to degrees Celcius (from Anolecomputing.com) function FtoC($value, $precision) { global $UOM; if ($UOM == 'F') { return round($value,$precision); } else { return round(($value - 32) * (5/9),$precision); } } // end function F to C // Autoscale function .. adjust scale to fit current conditions if need be. function autoscale($curtemp,$mintemp,$maxtemp) { global $Tmax,$Tmin,$Tincr,$TMajTick; $highest = max($curtemp,$Tmax,$maxtemp); $lowest = min($curtemp,$Tmin,$mintemp); while ($Tmax < $highest) { $Tmax += $TMajTick; } while ($Tmin > $lowest) { $Tmin = $Tmin - $TMajTick; } return; } ?>