Weather Station Hardware > Boltek/NexStorm Lightning Detectors
PHP to resize nexstorm.jpg/wasp2.png images w/cacheing
(1/1)
saratogaWX:
Just added a Boltek-PCI/NexStorm/StormVue to the site, and joined StrikeStarUS.
Lightning: http://saratoga-weather.org/lightning.php
StormVue: http://saratoga-weather.org/stormvue.php
My antenna is inside the house right now (too hot lately to venture on the roof for mounting), but should be relocated MUCH higher within the week.
Thanks to Tom (carterlake) and his tracreportshort.php program, there's a short summary above the image with the summary. I also wrote a small PHP to resize the nexstorm.jpg from 794x552 to 640x445 so it fits in my page design (limit 800px). Here it is if you'd like to use something similar.
resize-nexstorm-image.php
--- Code: ---<?php
// resize nexstorm.jpg from 794 x 552 to 640 x 445 to fit on screen
// Ken True - 25-Jul-2006
$Graphic = 'nexstorm.jpg';
$new_width = 640;
$new_height = 445;
$image = loadJPEG($Graphic); // fetch our map image
$MaxX = imagesx($image);
$MaxY = imagesy($image);
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $MaxX, $MaxY);
header("Content-type: image/jpeg"); // now send to browser
imagejpeg($image_p, null, 90);
imagedestroy($image);
imagedestroy($image_p);
exit;
function loadJPEG ($imgname) {
$im = @imagecreatefromjpeg ($imgname); /* Attempt to open */
if (!$im) { /* 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);
}
return $im;
}
?>
--- End code ---
To use, just put
--- Code: ---
<img src="resize-nexstorm-image.php" alt="NexStorm Display" width="640" height="445" />
--- End code ---
where you want the resampled image to appear.
neondesert:
--- Quote ---Just added a Boltek-PCI/NexStorm/StormVue to the site, and joined StrikeStarUS.
Lightning: http://saratoga-weather.org/lightning.php
StormVue: http://saratoga-weather.org/stormvue.php
--- End quote ---
Nice to have you aboard StrikeStar 8) !
--- Quote ---My antenna is inside the house right now (too hot lately to venture on the roof for mounting), but should be relocated MUCH higher within the week.
--- End quote ---
Too Hot :?: :!: ...Come on Ken, you just need to build up some callouses on your hands and you'll be ready to go :lol: :D .
Thanks, for the outstanding PHP code as usual :wink:
saratogaWX:
Ah, we have such a mild climate (usually) that my hands are caloused only on the fingertips from typing code and entries to forums :-)
But, with the major help of my son, the 18yr old brother of his girlfriend, and my brother-in-law, the detector is now in an Sch-40 ABS housing about 5 feet above the roof-line on the north eave of the house.
Also, thanks to krelvinaz on the WD forum -- he suggested I add caching to the resize script to lessen the server load, so here's the new code for resize-nexstorm-image.php
--- Code: ---<?php
// resize nexstorm.jpg from 794 x 552 to 640 x 445 to fit on screen
// Ken True - 25-Jul-2006
// modified for cacheing of the image, 3-Aug-2006
$Graphic = 'nexstorm.jpg';
$new_width = 640;
$new_height = 445;
$Cache = preg_replace('|\.jpg|','-cache.jpg',$Graphic);
$GraphicTime = filectime($Graphic);
$CacheTime = filectime($Cache);
if ($GraphicTime > $CacheTime) {
$image = loadJPEG($Graphic); // fetch our map image
$MaxX = imagesx($image);
$MaxY = imagesy($image);
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $MaxX, $MaxY);
imagejpeg($image_p, $Cache, 90);
imagedestroy($image);
imagedestroy($image_p);
}
if (file_exists($Cache)) {
header("Content-type: image/jpeg"); // now send to browser
readfile($Cache);
}
exit;
function loadJPEG ($imgname) {
$im = @imagecreatefromjpeg ($imgname); /* Attempt to open */
if (!$im) { /* 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);
}
return $im;
}
?>
--- End code ---
Ken
saratogaWX:
I discovered that the WASP2 png screen capture was also too wide (660px) to fit in the 640px allowed in my site design, so here's a companion script to handle resizing with caching of it too.
Both scripts, and Tom's (carterlake) excellent tracreportshort.php are used on my lightning page ( http://saratoga-weather.org/lightning.php )
usage:
--- Code: ---<img src="resize-wasp2-image.php" alt="Wide Area Storm Probe 2" width="640" height="562" />
--- End code ---
resize-wasp2-image.php
--- Code: ---<?php
// resize wasp2.png from 660 x 580 to 640 x 562 to fit on screen
// Ken True - 3-Aug-2006 webmaster@saratoga-weather.org
$Graphic = 'WASP2/wasp2.png';
$new_width = 640;
$new_height = 562;
$Cache = preg_replace('|\.png|','-cache.png',$Graphic);
$GraphicTime = filectime($Graphic);
$CacheTime = filectime($Cache);
if ($GraphicTime > $CacheTime) {
$image = loadPNG($Graphic); // fetch our map image
$MaxX = imagesx($image);
$MaxY = imagesy($image);
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $MaxX, $MaxY);
imagejpeg($image_p, $Cache, 90);
imagedestroy($image);
imagedestroy($image_p);
}
if (file_exists($Cache)) {
header("Content-type: image/png"); // now send to browser
readfile($Cache);
}
exit;
function loadPNG ($imgname) {
$im = @imagecreatefrompng ($imgname); /* Attempt to open */
if (!$im) { /* 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);
}
return $im;
}
?>
--- End code ---
Navigation
[0] Message Index
Go to full version