Skip to content

Instantly share code, notes, and snippets.

@nfreader
Created June 1, 2012 15:42
Show Gist options
  • Save nfreader/2853050 to your computer and use it in GitHub Desktop.
Save nfreader/2853050 to your computer and use it in GitHub Desktop.
spc-alert.php
Requirements
----
PHP with GD library
Bootstrap.min.css (optional)
Usage
----
Change $lat and $lon with the pixel coordinates of your location (refer to http://www.spc.noaa.gov/products/outlook/imgs/cities.gif) (currently set to Atlanta, Georgia)
Load spc-alert.php in your browser
Testing
----
Replace the $im url with http://www.spc.noaa.gov/products/outlook/archive/2011/day1otlk_v_20110426_2000.gif and update $lat/$lon accordingly
TODO
----
- Update $category arithmetic to handle warning polygon borders falling on $lat and $lon
- Set $lat and $lon via GET //Which defaults though?
<link href="bootstrap.min.css" rel="stylesheet">
<div class="container">
<?php
date_default_timezone_set('Europe/London');
$curr = date('Hi');
//echo "$curr <br>";
if ($curr > 0600) {
$time = '0600';
if ($curr > 1300) {
$time = '1300';
if ($curr > 1630) {
$time = '1630';
if ($curr > 2000) {
$time = '2000';
if ($curr > 0100) {
$time = '0100';
}
}
}
}
}
//echo $time;
$lat = 621;
$lon = 339;
$im = imagecreatefromgif("http://spc.noaa.gov/products/outlook/day1otlk_$time.gif");
$rgb = imagecolorat($im, $lat, $lon);
$colors = imagecolorsforindex($im, $rgb);
//var_export($colors);
/* echo '<style>body{background: rgb('.$colors['red'].' ,'.$colors['green'].', '.$colors['blue'].');}</style>'; */
$category = $colors['red'] + $colors['green'] + $colors['blue'];
//echo $category;
switch ($category) {
case 484: //Red
echo '<div class="alert" style="background: #e67f7f; border: 1px solid #cd0000; color: #cd0000;">Moderate risk of severe weather</div>';
break;
case 616: //Green
echo '<div class="alert" style="background: #c0e8c0; border: 1px solid #3c783c; color: #3c783c;">Thunderstorms possible</div>';
break;
case 619: //Yellow
echo '<div class="alert" style="background: #f6f67f; border: 1px solid #ff9600; color: #ff9600;">Slight chance of severe weather</div>';
break;
case 637: //Pink
echo '<div class="alert" style="background: #ff7fff; border: 1px solid #a348a3; color: #a348a3;">Extremely high risk of severe weather</div>';
break;
case 735: //White
echo '<div class="alert" style="background: white; border: 1px solid black; color: black;">No severe weather threat at this time </div>';
break;
}
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment