Author Topic: Weather Sticker PHP Script  (Read 39954 times)

0 Members and 1 Guest are viewing this topic.

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Weather Sticker PHP Script
« on: July 26, 2006, 08:01:18 PM »
Version 5.0 is now available:

http://scripts.anolecomputer.com/download.shtml

There are a lot changes starting with some new parameters added to config.txt:

Moved the icon placement parameters out into the config.txt file to make it easier to control placement of the icon. I meant to do this in 4.0 but somehow overlooked it. Here's what the section looks like from the new config.txt:

Code: [Select]

/***** ICON PLACEMENT: this section defines where the current      *****/
/***** conditions/forecast icon will be placed if you are using it *****/
// $sticker_icon_x: x coordinate on sticker of the upper left pixel of icon
// $sticker_icon_y: y coordinate on sticker of the upper left pixel of icon
$sticker_icon_x = '2';
$sticker_icon_y = '2';
// $banner_icon_x: x coordinate on banner of the upper left pixel of icon
// $banner_icon_y: y coordinate on banner of the upper left pixel of icon
$banner_icon_x = '300';
$banner_icon_y = '2';
// $banner_big_icon_x: x coordinate on banner_big of the upper left pixel of icon
// $banner_big_icon_y: y coordinate on banner_big of the upper left pixel of icon
$banner_big_icon_x = '2';
$banner_big_icon_y = '2';


Made it possible to choose your image format with a single parameter in config.txt. Options are gif, png, or jpeg. Background and current conditions icons have been provided for all three formats. Here's what the section looks like from the new config.txt:


Code: [Select]

/***** IMAGE FORMAT: defines the image format *****/
// The script supports 3 image formats: GIF, PNG, and JPG
// set $image_format for each as follows:
// for GIF: $image_format = 'gif';
// for PNG: $image_format = 'png';
// for JPEG: $image_format = 'jpeg';
$image_format = 'gif';


Probably the biggest change is the addition of current condition icons for VWS users! To use this feature the following tags are added to the VWS template file:

^climate_cconds1^,^vst144^,^vst145^

Thanks to Gordon C. @ http://oldlineweather.com for coming up with the list of possible values for ^climate_cconds1^ and making this possible!

Added some functionality to handle conditions where the data file is not present. Since its possible that the data file could be in the process of being uploaded at the time we try to get it, we can end up with a situation where we have no data. This can result in either script errors or blank images. The script is now much more robust in dealing with problems pulling the data file. Specifically:
 
If the data file is not found on the first attempt it will try again after a two second sleep.

If the data file is not found on the second attempt it will try again after another two second sleep.

If the data file is not found on the third attempt an image in the appropriate size (sticker, banner, banner_big) will be output indicating that there was no data available.


You can modify the text output in this instance by change the line (currently line 68 ) in sticker.php that reads:

Code: [Select]
nodataimage("Data Currently", "Unavailable");

Thanks to kenmtrue @ http://saratoga-weather.org/ for the idea/suggestion on handling the no data file issue.

And finally a couple of minor corrections:

Corrected some problems with icon images names.
Corrected text locations in the default images so they'll look a bit better initially.

One thing that I did not add that I had talked about doing was static images. If you need static images, it's probably best to tackle that through a cronjob. If you only want static images so you can use the banner in your signature on a phpBB forum or other location that will not allow php script calls, on a good way to accomplish that is through server redirects. Most control panels will let you do this through them or you can do it with an .htacess file if you are comfortable with that.

This will probably be the last major revision of the script. Of course, I'll continue to issue bug fixes, but the script is pretty much doing everything I want it to do for now.

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
New version coming soon complete with avatarly goodness!
« Reply #1 on: July 26, 2006, 08:06:45 PM »
Thanks to a suggestion from Drew (KCWX) I'm adding a fourth image type to the script, the dreaded avatar!

Basically, the script will have the capability to output a 100 X 100 avatar sized image in addition to the other three image sizes. Look to the left and you'll see it! As of this writing, it's a testing version but the code is all there with only some minor testing left to do and documentatin to update. I expect that will all be ready before the end of the week.

Offline Dragonfly

  • Senior Member
  • **
  • Posts: 68
    • http://www.crewe-weather.com
Weather Sticker PHP Script
« Reply #2 on: July 26, 2006, 09:09:36 PM »
Could somebody please post the URL for checking PHP and GD on a server. For some reason I can not get GD to work.

-Ingo

Offline NoQuitters

  • Forecaster
  • *****
  • Posts: 362
  • W0DLJ - 145.470
    • Overland Park Weather
Weather Sticker PHP Script
« Reply #3 on: July 26, 2006, 09:14:59 PM »
Quote
Thanks to a suggestion from Drew (KCWX) I'm adding a fourth image type to the script, the dreaded avatar!


All I have to say is...

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9296
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Weather Sticker PHP Script
« Reply #4 on: July 27, 2006, 12:14:49 AM »
Sure.. here's the test.php page:

Code: [Select]
<html>
<head>
<title>PHP test</title>
</head>
<body>
<h1>Does PHP work?</h1>

<?php echo "<h2>Yes, it does.  PHP Version " phpversion&#40;&#41; ."</h2>"; 
  
echo "<p>To run the WXSTICKER script, you need GD enabled in PHP.\n";
  echo 
"<br />Current GD status&#58;</p>\n";
  echo 
describeGDdyn&#40;&#41;;
  
// Retrieve information about the currently installed GD library
// script by phpnet at furp dot com &#40;08-Dec-2004 06&#58;59&#41;
//   from the PHP usernotes about gd_info
function describeGDdyn&#40;&#41; &#123;
 
echo "\n<ul><li>GD support&#58; ";
 if&
#40;function_exists&#40;"gd_info"&#41;&#41;&#123;
  
echo "<font color=\"#00ff00\">yes</font>";
  
$info gd_info&#40;&#41;;
  
$keys array_keys&#40;$info&#41;;
  
for&#40;$i=0; $i<count&#40;$keys&#41;; $i++&#41; &#123;
if&#40;is_bool&#40;$info[$keys[$i&#93;&#93;&#41;&#41; echo "</li>\n<li>" . $keys[$i&#93; ."&#58; " . yesNo&#40;$info[$keys[$i&#93;&#93;&#41;;
else echo "</li>\n<li>" $keys[$i&#93; ."&#58; " . $info[$keys[$i&#93;&#93;;
  
&#125;
 
&#125; else &#123; echo "<font color=\"#ff0000\">NO</font>"; &#125;
 
echo "</li></ul>";
&
#125;
function yesNo&#40;$bool&#41;&#123;
 
if&#40;$bool&#41; return "<font color=\"#00ff00\"> yes</font>";
 
else return "<font color=\"#ff0000\"> no</font>";
&
#125;


?>


<p>If you don't see "Yes, it does." above, then PHP is not enabled.</p>
</body>
</html>


If you have PHP and GD you should see something like this:
Quote
Does PHP work?
Yes, it does. PHP Version 4.4.2

To run the WXSTICKER script, you need GD enabled in PHP.
Current GD status:

    * GD support: yes
    * GD Version: 2.0 or higher
    * FreeType Support: yes
    * FreeType Linkage: with freetype
    * T1Lib Support: no
    * GIF Read Support: yes
    * GIF Create Support: yes
    * JPG Support: yes
    * PNG Support: yes
    * WBMP Support: yes
    * XBM Support: no
    * JIS-mapped Japanese Font Support: no

If you don't see "Yes, it does." above, then PHP is not enabled.


If you only see
Quote
Does PHP work?
If you don't see "Yes, it does." above, then PHP is not enabled.

 or worse, a bunch of stuff like
Quote
<?php echo "<h2>Yes, it does.  PHP Version " . phpversion() ."</h2>";
  echo "<p>To run the WXSTICKER script, you need GD enabled in PHP.\n";
  echo "<br />Current GD status:</p>\n";
  echo describeGDdyn();
...
the HTML is not parsed by the PHP interpreter and is treated as badly formed HTML -- In other words, PHP is not working on your site.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Version 5.2 is now available
« Reply #5 on: July 27, 2006, 01:34:27 PM »
Version 5.2 is now available and can be downloaded at:

http://scripts.anolecomputer.com/download.shtml

This new version includes a fourth image size designed to be used as a forum avatar...

<<<-----------------------  Look over there.

Thanks to Drew (KCWX) for the suggestion.

Avatar image size is 100px X 100px. The following changes are made to config.txt to enable this new image size:

The section where the current conditions icon is set has added some additional lines and now looks like this:

Code: [Select]

/***** ICON PLACEMENT: this section defines where the current      *****/
/***** conditions/forecast icon will be placed if you are using it *****/
// $sticker_icon_x: x coordinate on sticker of the upper left most pixel of icon
// $sticker_icon_y: y coordinate on sticker of the upper left most pixel of icon
$sticker_icon_x = '2';
$sticker_icon_y = '2';
// $banner_icon_x: x coordinate on banner of the upper left most pixel of icon
// $banner_icon_y: y coordinate on banner of the upper left most pixel of icon
$banner_icon_x = '300';
$banner_icon_y = '2';
// $banner_big_icon_x: x coordinate on banner_big of the upper left most pixel of icon
// $banner_big_icon_y: y coordinate on banner_big of the upper left most pixel of icon
$banner_big_icon_x = '2';
$banner_big_icon_y = '2';
// $avatar_icon_x: x coordinate on avatar of the upper left most pixel of icon
// $avatar_icon_y: y coordinate on avatar of the upper left most pixel of icon
$avatar_icon_x = '2';
$avatar_icon_y = '2';


A new function "write_avatar" was added to write the data onto the avatar image:

Code: [Select]

/*****************************************************************************/
/***** write_avatar: This function writes your values onto the sticker. *****/
/*****************************************************************************/
function write_avatar() {
  // let's start by defining some global variables that will be passed between
  // functions. This is kind of clunky!
  // NOTE: IF YOU ADD ADDITIONAL COLORS YOU'LL NEED TO ADD THEM HERE TOO!
  global $color1, $color2, $color3, $color4, $color5, $date, $time, $temp, $degree_units,
         $winds, $wind_units, $gust, $raintoday, $rain_units, $barom, $barom_units,
         $baromtrendwords, $dewpt, $humidity, $heatindex, $heat_index_threshold,
         $windchill, $wind_chill_threshold, $sticker_icon_x, $sticker_icon_y;

  // this section does the heat index and wind chill
  // it figures out what to show, wind chill, heatindex or nothing
  // depending upon your settings
  switch (TRUE){
  // if windchill is <= $wind_chill_threshold we'll output it
  case ($windchill <= $wind_chill_threshold):
       $feelslike = "WindCh: $windchill$degree_units";
       imagecenteredtext(50, 50, "$feelslike", 1, 7, $color3, 0);
  break;
  // if heat index >= $heat_index_threshold we'll output it
  case ($heatindex >= $heat_index_threshold):
       $feelslike = "HeatIdx: $heatindex$degree_units";
       imagecenteredtext(50, 50, "$feelslike", 1, 7, $color1, 0);
  break;
  } // end switch

  // this section controls what is written to the image, where it is written.
  // see the explanation above for details on what each parameter represents
  imagecenteredtext(65, 10, "Title Here", 2, 8, $color2, 0);
  imagecenteredtext(65, 20, "Curr Wx", 2, 8, $color2, 0);
  imagecenteredtext(50, 40, "$temp$degree_units", 5, 14, $color4, 0);
  imagecenteredtext(50, 60, "Rain: $raintoday$rain_units", 3, 9, $color3, 0);
  imagecenteredtext(50, 72, "$winds", 3, 9, $color4, 0);
  imagecenteredtext(50, 82, "$barom$barom_units", 1, 8, $color4, 0);
  imagecenteredtext(50, 96, "$date $time", 1, 7, $color2, 0);

} /***** end function write_avatar *****/


These are the only changes in this version.

Offline NoQuitters

  • Forecaster
  • *****
  • Posts: 362
  • W0DLJ - 145.470
    • Overland Park Weather
Weather Sticker PHP Script
« Reply #6 on: July 27, 2006, 03:00:18 PM »
Works like a charm. Thanks Larry!! :D

Offline Dragonfly

  • Senior Member
  • **
  • Posts: 68
    • http://www.crewe-weather.com
Weather Sticker PHP Script
« Reply #7 on: July 27, 2006, 07:51:04 PM »
Thanks Ken, I knew I had PHP running guess now I need to figure out the GD installation

-Ingo

Offline ncpilot

  • Forecaster
  • *****
  • Posts: 937
    • Monkey Junction Weather
Weather Sticker PHP Script
« Reply #8 on: July 28, 2006, 09:43:47 AM »
Is there a way.........to....

I'm using free hosting right now, so no PHP on the server. I'd like to try to implement a weathersticker, but process it on my PC, then upload the image to my host--I'm looking at doing it on 15 min intervals, same as my current page update--not real time.

Before I try to convert the code to PERL (has anyone done this already?), is it possible to run PHP on my home computer (just generate the image, then upload to host)? (without a lot of pain?)

I'll most likely, eventually, get a real hosting service, but until then...
Marc
Wilmington, NC
"Monkey Junction Weather"
Davis VP2 wireless, WeatherLink

Offline Dragonfly

  • Senior Member
  • **
  • Posts: 68
    • http://www.crewe-weather.com
Weather Sticker PHP Script
« Reply #9 on: July 28, 2006, 09:54:20 AM »
I am having the same problem with Earthlink. Although I am runing my own server I'm having an issue with the GD. So for the time being my sticker is generated with GraphWeather and the Weatherlink plugin, not perfect but it works.

-Ingo

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9296
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Weather Sticker PHP Script
« Reply #10 on: July 28, 2006, 10:35:20 AM »
According to the PHP site ( www.php.net ), there is a command-line interface for PHP http://us2.php.net/manual/en/features.commandline.php

You can download the latest windows binary for 4.4.2 in .zip format, and give it a try :-)

To save the sticker to a graphic file, you just have to change the lines that say (in sticker.php V5.2):
Code: [Select]
// send header to browser
switch (TRUE) {
  case ($image_format == 'gif') :
       header('Content-type: image/gif');
       imagegif($img);
  break;
  case ($image_format == 'png') :
       header('Content-Type: image/png');
       imagepng($img);
  break;
  case ($image_format == 'jpeg') :
       header('Content-type: image/jpeg');
       imagejpeg($img);
  break;
} // end switch


to have a filename as the second argument of the imagennnn function like this:
Code: [Select]
// send header to browser
switch (TRUE) {
  case ($image_format == 'gif') :
       header('Content-type: image/gif');
       imagegif($img,"./current-sticker.gif");
  break;
  case ($image_format == 'png') :
       header('Content-Type: image/png');
       imagepng($img,"./current-sticker.png");
  break;
  case ($image_format == 'jpeg') :
       header('Content-type: image/jpeg');
       imagejpeg($img,"./current-sticker.jpg");
  break;
} // end switch


That will save a current-sticker.[gif|png|jpg] file in the sticker.php directory.  You could then upload it to your website using WD or VWS.

It's not recommended you do this mod on the website though.. there may be a file-lock problem if more than one browser is accessing the script at the same time (two or more scripts may try to write the same file).  But for a command line thing, it should work fine (no conflicts there).

BTW.. I'd used a similar technique to save the www.wrh.noaa.gov Icons stamped with a PoP for my get-nws-forecast-test.php (Tom's advforecast.php script adapted for Western Region NOAA).

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Weather Sticker PHP Script
« Reply #11 on: July 28, 2006, 01:47:42 PM »
It can be done on a local machine but it's not exactly an easy task. You need to:

1) install a webserver like Apache on the local machine
2) install PHP with GD support on the local machine.

The second part that makes it difficult is that the script doesn't generate static images on its own so you'd need to:

1) Come up with a script that runs the sticker script and create a file from the results that it outputs. I can help you here.
2) Have this happen on a scheduled basis, possibly using the windows task scheduler. I say possibly because I've never tried running a PHP script with the task scheduler but I can't think of any reason why it shouldn't work.

EDIT: Seems Ken and I were typing at the same time. His solution for generating the static image is much easier than what I would have done. You'll still have to schedule it though.

On the command line interface I _thought_ that you still had to install Apache (or another web server) to make that work. But I very easily could be wrong.

Offline ncpilot

  • Forecaster
  • *****
  • Posts: 937
    • Monkey Junction Weather
Weather Sticker PHP Script
« Reply #12 on: July 28, 2006, 03:36:53 PM »
Ugh! As I might have suspected, it sounds like it would be easier to just get hosted (but not HOSED...) with a service that supports PHP... which will happen one day... as much as I'd just LOVE  :roll: to learn the hard way by  installing Apache and PHP on my home computer, I think I'll pass for now...

If I'm looking to just generate a relatively static avatar or banner, couldn't I use something like ImageSalsa? For now I don't so much care about generating a "real-time" image. There are probably a few other packages that would also work like ImageSalsa...

Actually, after looking again at the ImageSalsa website, and from hearing some support issue stories about Ambient, and the following:

"Veo Observer Network Camera -- Does not provide static image URL required to load images from network cameras.  I've asked the company for network communications protocol that could be incorporated into ImageSalsa, but have received no response."

This is completely untrue, and I emailed Ambient about it, and gave them the URL to get an image off the Veo cam (which I own), yet they still claim you can't get a static image off of it...

blah...
Marc
Wilmington, NC
"Monkey Junction Weather"
Davis VP2 wireless, WeatherLink

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Weather Sticker PHP Script
« Reply #13 on: July 28, 2006, 03:45:38 PM »
Yes, lots of folks use ImageSalsa for exactly that purpose.

Offline ncpilot

  • Forecaster
  • *****
  • Posts: 937
    • Monkey Junction Weather
Weather Sticker PHP Script
« Reply #14 on: July 28, 2006, 03:46:39 PM »
Oops, I was in the middle of an edit when you replied my green lizard weather watcher anole...  :lol:
Marc
Wilmington, NC
"Monkey Junction Weather"
Davis VP2 wireless, WeatherLink

Offline Dragonfly

  • Senior Member
  • **
  • Posts: 68
    • http://www.crewe-weather.com
Weather Sticker PHP Script
« Reply #15 on: July 28, 2006, 04:17:14 PM »
Thanks Guys.
I upgraded my PHP to 5.x with GD support and PHP work but I believe the problem might be my webserver [xitami].
So for now I guss I'll stick with GraphWeather for my sticker

-Ingo

Offline SLOweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 3456
    • Weatherelement Moline IL
Weather Sticker PHP Script
« Reply #16 on: July 28, 2006, 06:03:16 PM »
Quote from: "Dragonfly"
Thanks Guys.
I upgraded my PHP to 5.x with GD support and PHP work but I believe the problem might be my webserver [xitami].
So for now I guss I'll stick with GraphWeather for my sticker


What problems are you having? Got all the permissions set right? That always messes me up.

Offline Ravenstar

  • Senior Contributor
  • ****
  • Posts: 180
    • http://veronaweather.com
Weather Sticker PHP Script
« Reply #17 on: July 28, 2006, 09:05:56 PM »
pilot I'd be gald to work with ya on a sticker sounds like you're stuck between a rock and a hard place. It's not like Ken's and Anole's (hope I'm not leaving anyone out and I'm not trying to steal anyone's thunder) but we could work on the design of it. All you'd have to do is get the data to me. I'm currently grabbing data from other sites for my custom graphs very similier to RSS feed. Works like a champ and very simple to do.

Up to you.


Vantage pro 2 (wireless)

Offline weatheroz

  • Senior Contributor
  • ****
  • Posts: 216
    • http://www.jimboombaweather.com
Weather Sticker PHP Script
« Reply #18 on: July 29, 2006, 08:52:45 AM »
Quote from: "ncpilot"


If I'm looking to just generate a relatively static avatar or banner, couldn't I use something like ImageSalsa? For now I don't so much care about generating a "real-time" image. There are probably a few other packages that would also work like ImageSalsa...


Yep, that's what I use for my avatars and sig's here.
Brendan,
vk4blp
IRLP 6857 Echolink 672767


Offline Dragonfly

  • Senior Member
  • **
  • Posts: 68
    • http://www.crewe-weather.com
Weather Sticker PHP Script
« Reply #19 on: July 29, 2006, 03:36:35 PM »
Thanks again, Had to dump PHP and did a clean install.

Does PHP work?
Yes, it does. PHP Version 5.1.4
To run the WXSTICKER script, you need GD enabled in PHP.
Current GD status:

GD support: yes
GD Version: bundled (2.0.28 compatible)
FreeType Support: yes
FreeType Linkage: with freetype
T1Lib Support: yes
GIF Read Support: yes
GIF Create Support: yes
JPG Support: yes
PNG Support: yes
WBMP Support: yes
XPM Support: no
XBM Support: yes
JIS-mapped Japanese Font Support: no
If you don't see "Yes, it does." above, then PHP is not enabled.

Now to building the sticker in PHP

-Ingo

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Version 5.3 now available
« Reply #20 on: July 30, 2006, 09:47:29 AM »
Version 5.3 is now available:

http://scripts.anolecomputer.com/download.shtml

NOTE: There is no reason to download this version if you have version 5.2 up and working. No changes have been made to the actual script or configuration.

The script archive now includes a web page you can upload to your server to verify PHP and GD support on your server. This file is named:
PHP_verify.php

Simply upload it to your server and call it with a URL to verify if:
    PHP is installed
    Which PHP version you are running
    If GD support is installed
    Details about the GD install
    More information than you really want to know about your PHP install


Additionally, I've put together a web page with more details on setting up and using the script:
http://scripts.anolecomputer.com/wxsticker/

Offline Dragonfly

  • Senior Member
  • **
  • Posts: 68
    • http://www.crewe-weather.com
Weather Sticker PHP Script
« Reply #21 on: July 30, 2006, 01:03:12 PM »
anole,
I get a 404 error when trying to download from your link

-Ingo

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Weather Sticker PHP Script
« Reply #22 on: July 30, 2006, 01:31:48 PM »
Are you still getting it? I'm not seeing any problems here and I've seen several downloads since posting.

Offline Dragonfly

  • Senior Member
  • **
  • Posts: 68
    • http://www.crewe-weather.com
Weather Sticker PHP Script
« Reply #23 on: July 30, 2006, 02:32:10 PM »
Yes I am.
Not Found
The requested URL /wxsticker/ was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


--------------------------------------------------------------------------------

Apache/1.3.33 Server at 66.78.27.230 Port 80

Reset the modem for another IP but still the same

-Ingo

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Weather Sticker PHP Script
« Reply #24 on: July 30, 2006, 03:18:02 PM »
If you go here:
http://scripts.anolecomputer.com/

and click on the Weather Sticker link what happens?