converted to F if needed # relative Humidity # Calculation: Chandler Burning index # Output: Graphic .png with settings and correct colors /words # Image used 5 graphics for each of the 5 danger levels # default located in the same directory as the script # optional a TTF font-file, located in the same folder as the images #----------------------------------------------------------------------- # SETTINGS: # $fw_folder = './'; // same folder as the script is executed from #$fw_folder = './firedanger/'; // script is included from another folder #$ws_font_file = $fw_folder.'PFDinDisplayPro-Bold.ttf'; $ws_font_file = $fw_folder.'arial.ttf'; # #----------------------------------------------------------------------- # # Check parameters either by php variables or wsFireDanger.php?fwuom=c,&fwtemp=12.3&fwhum=45.6 # if (!isset ($fw_uom) ) { $fw_uom = 'c'; } if (isset($_REQUEST['fwuom']) && $_REQUEST['fwuom'] <> '') { $fw_uom = strtolower ($_REQUEST['fwuom']); if ($fw_uom <> 'c') { $fw_uom = 'f'; } } if (isset($_REQUEST['fwtemp'])) { $fwtemp = (float) $_REQUEST['fwtemp']; } if (isset($_REQUEST['fwhum'])) { $fwhum = (float) $_REQUEST['fwhum'];} if (isset($_REQUEST['lang'])) { $string = trim((string) $_REQUEST['lang']); $lang = substr ($string.' ',0,2);} if (!isset ($fwtemp) || !isset ($fwhum) ) { echo '

Missing variable for calculating CBI

'; return;} ws_fw_trans_setup (); if ($fw_uom == 'f') // normalize from f to c { $cTemp = 5*($fwtemp - 32) / 9;} else { $cTemp = 1.0 * $fwtemp;} $fwtemp = round ($fwtemp, 0); $fwhum = round ($fwhum, 0); #-------calculate Chandler Index --------------------------------------- #CBI = (((110 - 1.373*RH) - 0.54 * (10.20 - T)) * (124 * 10**(-0.0142*RH)))/60 # $cbi = (((110 - 1.373 * $fwhum) - 0.54 * (10.20 - $cTemp)) * (124 * pow(10,(-0.0142*$fwhum))))/60; # find correct image for the Chandler Index #echo $cbi; exit; if ($cbi > 160 ) { $cbitxt = 'EXTREME'; $cbiimg = 'BosBrandGevaarExtreem.png';} elseif ($cbi >= 100 ) { $cbitxt = 'VERY HIGH'; $cbiimg = 'BosBrandGevaarHeelHoog.png';} elseif ($cbi >= 50 ) { $cbitxt = 'HIGH'; $cbiimg = 'BosBrandGevaarHoog.png';} elseif ($cbi >= 30 ) { $cbitxt = 'MODERATE'; $cbiimg = 'BosBrandGevaarMatig.png';} else { $cbitxt = 'LOW'; $cbiimg = 'BosBrandGevaarLaag.png';} #if ($cbi > 78 ) { $cbitxt = 'EXTREME'; $cbiimg = 'BosBrandGevaarExtreem.png';} #elseif ($cbi >= 47 ) { $cbitxt = 'VERY HIGH'; $cbiimg = 'BosBrandGevaarHeelHoog.png';} #elseif ($cbi >= 29 ) { $cbitxt = 'HIGH'; $cbiimg = 'BosBrandGevaarHoog.png';} #elseif ($cbi >= 18 ) { $cbitxt = 'MODERATE'; $cbiimg = 'BosBrandGevaarMatig.png';} #else { $cbitxt = 'LOW'; $cbiimg = 'BosBrandGevaarLaag.png';} #if ($cbi > 40 ) { $cbitxt = 'EXTREME'; $cbiimg = 'BosBrandGevaarExtreem.png';} #elseif ($cbi >= 4 ) { $cbitxt = 'VERY HIGH'; $cbiimg = 'BosBrandGevaarHeelHoog.png';} #elseif ($cbi >= 3 ) { $cbitxt = 'HIGH'; $cbiimg = 'BosBrandGevaarHoog.png';} #elseif ($cbi >= 2 ) { $cbitxt = 'MODERATE'; $cbiimg = 'BosBrandGevaarMatig.png';} #else { $cbitxt = 'LOW'; $cbiimg = 'BosBrandGevaarLaag.png';} $cbi = round($cbi,0); // to diplay on image we do not need a floatingpoint value $fwimg = imagecreatefrompng($fw_folder.$cbiimg); imageAlphaBlending($fwimg, true); imageSaveAlpha($fwimg, true); $degree_units = utf8_decode( (($fw_uom == 'f')?'°F':'°C') ); $color_red = imagecolorallocate($fwimg,0,0,0); $color_green = imagecolorallocate($fwimg,0,0,0); $color_white = imagecolorallocate($fwimg,0,0,0); $color_black = imagecolorallocate($fwimg,0,0,0); #imagestring($fwimg, 4, 35, 108, $fwtemp.$degree_units, $color_green); #imagestring($fwimg, 4, 70, 108, $fwhum.'%', $color_green); #imagestring($fwimg, 5, 40, 120, 'CBI: '.$cbi, $color_red); $string = $fwtemp.$degree_units.' '.$fwhum.'%'; ws_center_text($fwimg, 3, 132/2, 118,$string,$color_green); $string = 'CBI: '.$cbi; if ($cbitxt == 'HIGH') {$cbi_color = $color_black; } else {$cbi_color = $color_white; } ws_center_text($fwimg, 4, 132/2, 130,$string,$color_red); ws_center_text($fwimg, 4, 132/2, 97,$fw_lang[$cbitxt],$cbi_color); ws_center_text($fwimg, 4, 132/2, 15,$fw_lang['FIRE DANGER'],$color_white); # --------------------------------- header("Content-type: image/png"); imagepng($fwimg,NULL); imagedestroy($fwimg); # ---based on function imagecenteredtext() --------------------- # Original uthor UNKNOWN, please mail me correct author name if you know him / her # adapted to more look like built-in imagestring function # bool imagestring ( resource $image , int $font , int $x , int $y , string $string , int $color ) # # Text centering function for image creation centers on provided x, y coordinates # You must pass all parameters even if you aren't using them. # $x = x coordinate where the text will be centered # $y = y coordinate where the text will be centered # $text = the text to be written # $size = font size for built-in GD fonts (1,2,3,4, or 5) # $ttfsize = font size for ttf fonts. Use just like you would in a word processor # $color = color as defined in the allocate colors section below # $angle = for ttf fonts, determines the angle for the text. # function ws_center_text($im, $size, $x, $y, $text, $color, $ttfsize= 10 , $angle= 0) { global $ws_font_file, $anti_alias ; # if FreeType is not supported OR $ws_font_file is set to none, we'll use the GD default fonts if (!isset ($ws_font_file)) { $ws_font_file = 'none';} if (!isset ($anti_alias)) { $anti_alias = 'on';} $gdinf = gd_info(); if ( ($gdinf["FreeType Support"] == 0) || ($ws_font_file == "none")) { $x -= (imagefontwidth($size) * strlen($text)) / 2; $y -= (imagefontheight($size)) / 2; imagestring($im, $size, $x, $y - 3, $text, $color); } // end use built in fonts else { // otherwise we'll use the truetype font defined in $ws_font_file $box = imagettfbbox ($ttfsize, $angle, $ws_font_file, $text); $x -= ($box[2] - $box[0]) / 2; $y -= ($box[3] - $box[1]) / 2; if ($anti_alias == 'off') { imagettftext ($im, $ttfsize, $angle, $x, $y, -$color, $ws_font_file, $text);} else { imagettftext ($im, $ttfsize, $angle, $x, $y, $color, $ws_font_file, $text);} } // end use the truetype font } // eof ws_center_text # function ws_fw_trans_setup () { global $lang, $fw_lang; if (!isset ($lang) ) {$lang = 'nl';} if ($lang == 'en') { $fw_lang['EXTREME'] = 'Extreme Risk'; $fw_lang['VERY HIGH'] = 'Very High Risk'; $fw_lang['HIGH'] = 'High Risk'; $fw_lang['MODERATE'] = 'Moderate Risk'; $fw_lang['LOW'] = 'Low Risk'; $fw_lang['FIRE DANGER'] = ''; } # else { $fw_lang['EXTREME'] = 'Extreem Risico'; $fw_lang['VERY HIGH'] = 'Heel Hoog Risico'; $fw_lang['HIGH'] = 'Hoog Risico'; $fw_lang['MODERATE'] = 'Matig Risico'; $fw_lang['LOW'] = 'Laag Risico'; $fw_lang['FIRE DANGER'] = ''; } if ($lang == 'de') { $fw_lang['EXTREME'] = 'Extremes Risiko'; $fw_lang['VERY HIGH'] = 'Sehr Hohes Risiko'; $fw_lang['HIGH'] = 'Hohes Risiko'; $fw_lang['MODERATE'] = 'Mäßig Risiko'; $fw_lang['LOW'] = 'Niedriges Risiko'; $fw_lang['FIRE DANGER'] = ''; } if ($lang == 'fr') { $fw_lang['EXTREME'] = 'Risque extrême'; $fw_lang['VERY HIGH'] = 'Risque très élevé'; $fw_lang['HIGH'] = 'Risque élevé'; $fw_lang['MODERATE'] = 'Risque Modéré'; $fw_lang['LOW'] = 'Faible Risque'; $fw_lang['FIRE DANGER'] = ''; } } // eof ws_fw_trans_setup