I'm throwing this script out not as a finished product (although it does it's specific job well so far), but more as food for other ideas for similar scripts. It's certainly not a polished as other scripts, (and there are probably better ways to do some things) but I think there are enough comments in it for anyone with a smackerel of PHP to follow along and modify it as desired.
It includes some commented out testing code. Post any other ideas you come up with for such a script.
I've been working on some fire weather page for a client, and I haven't been able to find a text source of the
Haines Index values, which is "used to indicate the potential for wildfire growth by measuring the stability and dryness of the air over a fire."
It's also pretty hard to find the right data easily to calculate it locally.
But that link above has a link to this map:
I did a little research and found that PHP has an imagecolorat command that will output the decimal color value of a pixel in an image.
So I wrote this script to get the color value and then turn it back into a Haines number and adjective. It's not perfect. I hard-coded the color values, so I'm screwed if they change them at all. I did find out that the colors on the map today don't exactly match the ones in the legend. I'll have to test it for a while to see if the colors change slightly from day to day.
The pixel this version checks is just about at the middle of this part of the image:
To see the simple output, it's currently available to run at
http://fire.cambriacsd.org/fire/haines.php unless I'm playing with it or broke it.
<?php
// Second alpha release 070801
// This SLOweatherscript loads a color coded map, such as the one at
//
http://www.fs.fed.us/land/wfas/haines.gif, reads the color at a
// specified pixel, and converts that color value back into a text value.
// The base routine will work on jpgs and png with no problem. However, GIFs
// apparently need to be upsampled before checking the color value.
// To modify this for use other than the Haines Index GIF, load the desired
// image into an editing program and determine the X and Y coordinates of the
// pixel who's color you want the value of. Then, run this script on other known
// color locations on the image to determine the values of different colors.
// Jpgs may take a little more work, due to the jpeg color artifacts present
// around and in colored areas causing the integer color value to shift.
// There are lots of other ways to used the recovered color info, but this
// version only compares it to 5 known colors.
// Create a blank true color image the same size as the GIF.
$dimg=imagecreatetruecolor(782,580);
// Get the image.
$simg = imagecreatefromgif("
http://www.fs.fed.us/land/wfas/haines.gif");
// Upsample the GIF to the true color blank.
imagecopy($dimg,$simg,0,0,0,0,782,580);
// The script will fail if either the X or Y value for the location is
// less than 0, or greater than the corresponding size value of the image
// in the line above. Enter the pixel location X and Y below.
$rgb = imagecolorat($dimg, 48, 300);
// Get the decimal values of each component color
// $r = ($rgb >> 16) & 0xFF;
// $g = ($rgb >> Cool & 0xFF;
// $b = $rgb & 0xFF;
// Destroy the images
imagedestroy($simg);
imagedestroy($dimg);
// This is for testing and to determine the color
// values.
// echo $rgb;
//echo $r;
//echo $g;
//echo $b
// Define the Haines GIF colors
$black= "0";
$blue ="65535";
$dkgreen ="3912561";
$green = "65280";
$yellow = "16776960";
$orange = "16766720";
$red = "16737094";
//Sort out the Haines Index
if ($rgb == $dkgreen) {
$hainestext = "Very Low";
$hainesvalue= "2";
} elseif ($rgb == $green) {
$hainestext = "Very Low";
$hainesvalue= "3";
} elseif ($rgb == $yellow) {
$hainestext = "Low";
$hainesvalue= "4";
} elseif ($rgb == $orange) {
$hainestext = "Moderate";
$hainesvalue= "5";
} elseif ($rgb == $red) {
$hainestext = "High";
$hainesvalue= "6";
} elseif ($rgb == $blue) {
$hainestext = "Water";
$hainesvalue= "-";
} elseif ($rgb == $black) {
$hainestext = "Text or Border";
$hainesvalue= "-";
} else
{
$hainestext = "Unknown";
$hainesvalue= "-";
}
// Output the value and text
echo $hainesvalue, " ";
echo "$hainestext";
?>