Welcome to the new home of the Cumulus Support forum.

Latest Cumulus release v1.9.4 (build 1099) - Nov 28 2014
Latest Cumulus MX release - v3.0.0 build 3043 Jan 20 2017. See the Wiki for download

Cumulus PHP-GD Avatar

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderators: daj, TNETWeather

User avatar
mcrossley
Posts: 5209
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Stretch Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Cumulus PHP-GD Avatar

Post by mcrossley » Tue 04 Jun 2013 9:46 pm

As a point of interest, to make using the avatar and banner scripts easier on forums etc, I addded a little code to my .htaccess file on the web server so you can call them as ------/avatar.jpg or ----/avatar.png or .gif

The web server will then redirect the call to the script and pass the required image format to the script as a parameter. Whatever is loading the image is unaware that any PHP is invoved.

Code: Select all

#Banner image redirection to script

RewriteEngine On
RewriteRule ^banner.(gif|jpg|png)$ banner.php?format=$1 [NC,L]
RewriteRule ^(avatar[0-9]+).(gif|jpg|png)$ $1.php?format=$2 [NC,L]
Eg. avatar100.php called as avatar100.png...
Image

Edit: I just remembered that I modded Ken's scripts slightly to enable the passing on the format parameter.
So in teh avatar.php script after the $DATA =, add the additional parameter handling...

Code: Select all

// Read data into array
$DATA = get_raw($SITE['hloc'] . $SITE['datafile'],' ');

// Has an output format paramter been passed to the script?
if (isset($_GET['format']) && $_GET['format'] !== '') {
	$SITE['format'] = strtolower($_GET['format']);
}

User avatar
SpireWeather
Posts: 58
Joined: Fri 17 Jun 2011 7:43 pm
Weather Station: Davis Vantage Vue
Operating System: Windows XP SP3
Location: Wimborne Minster UK
Contact:

Re: Cumulus PHP-GD Avatar

Post by SpireWeather » Tue 04 Jun 2013 10:18 pm

So what exactly would I add to my avatar php script to add max temp, min temp & pressure trend?

Any further advice for a novice would be very much appreciated.
Simon, WessexWeather
Image

User avatar
beteljuice
Posts: 2510
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: XP SP3 - honest
Location: Dudley, West Midlands, UK

Re: Cumulus PHP-GD Avatar

Post by beteljuice » Tue 04 Jun 2013 10:36 pm

OK - a little bit awkward as the avatar is a stripped down version of the banner and doesn't 'declare' variable names, but just uses the data array (See http://wiki.sandaysoft.com/a/Realtime.txt for format)

However: because of the lack of 'realestate' for all the info you want it is necessary to resize the original temp. I also changed the colour of the date to white so it can be seen !

This is from YOUR realtime.txt
Image Here's the zip file:
avatar-1.0.zip
BTW - It is bad practise to have directory names with <spaces> in them. eg ttf fonts/ ;)

PS. the beteljuice was just taking a mental break from all the coding bits flying around inside his skull :bash:
You do not have the required permissions to view the files attached to this post.
Image
......................Imagine, what you will KNOW tomorrow !

User avatar
SpireWeather
Posts: 58
Joined: Fri 17 Jun 2011 7:43 pm
Weather Station: Davis Vantage Vue
Operating System: Windows XP SP3
Location: Wimborne Minster UK
Contact:

Re: Cumulus PHP-GD Avatar

Post by SpireWeather » Wed 05 Jun 2013 5:27 am

Beteljuice, that's very kind. I suppose I could have just created a new banner - didn't think of that.

Thank you so much.

Regards,
Simon, WessexWeather
Image

CrasHBoneS
Posts: 96
Joined: Fri 06 Jan 2012 10:49 am
Weather Station: PCE-FWS20
Operating System: Windows XP SP3
Location: Bellaria Igea Marina (RN)
Contact:

Re: Cumulus PHP-GD Avatar

Post by CrasHBoneS » Wed 05 Jun 2013 8:38 am

My little suggestion

In many parts of the code there is "100" that is the width of the banner

example
// Print Date Center Bottom
$text = $DATA[0] . ' @ ' . $DATA[1];
if ($SITE['usettf'] == "yes" ) {
$size = 7;
imagettftextbox($im, $size, 0, 0, 86, $black, $font2, $text, 100, "center");
} else {
center_text ( $im, 1, $text, 89, $black);
}

If I use 150 as width in configuration, I must replace in the php file 100 with 150
Maybe 100 must be replaced "$SITE['image_width']"

User avatar
beteljuice
Posts: 2510
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: XP SP3 - honest
Location: Dudley, West Midlands, UK

Re: Cumulus PHP-GD Avatar

Post by beteljuice » Wed 05 Jun 2013 10:28 am

@Simon - Don't you want the zip to see whats been done ?

@CrasHBoneS
In many parts of the code there is "100" that is the width of the banner

imagettftextbox($im, $size, 0, 0, 86, $black, $font2, $text, 100, "center");

If I use 150 as width in configuration, I must replace in the php file 100 with 150
beteljuice apology - the next bit is rubbish !
Not absolutely.

150 would be the Maximum width available.

The parameter in the imagegettftextbox() function is the max. width before wrapping of the supplied text.

It really is eg.

Code: Select all

		imagettftextbox($im, $size, 0, 0, 1, $green, $font3, $text, ['image_width'], "right");
These are the (ttf font) options for right justified text.

['image_width'] is the furthermost right 'edge' that the text justifies to (less a 5px margin).
So if you replace ['image_width'] with your pretend right-hand (text) extreme, everything should be hunky dory - I think
Last edited by beteljuice on Thu 06 Jun 2013 11:05 pm, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !

User avatar
SpireWeather
Posts: 58
Joined: Fri 17 Jun 2011 7:43 pm
Weather Station: Davis Vantage Vue
Operating System: Windows XP SP3
Location: Wimborne Minster UK
Contact:

Re: Cumulus PHP-GD Avatar

Post by SpireWeather » Wed 05 Jun 2013 11:04 am

Yes Beteljuice, I will be downloading the zip this evening after work.

Thanks again,
Simon, WessexWeather
Image

User avatar
SpireWeather
Posts: 58
Joined: Fri 17 Jun 2011 7:43 pm
Weather Station: Davis Vantage Vue
Operating System: Windows XP SP3
Location: Wimborne Minster UK
Contact:

Re: Cumulus PHP-GD Avatar

Post by SpireWeather » Fri 07 Jun 2013 4:18 pm

Thanks to beteljuice's help I have the extra parameters displayed on my avatar...

Image

A couple of further questions: -

1. The pressure trend as it stands is a bit meaningless to a lay person. How could this be translated to text like the #pressuretrend tag?

2. Over what period is the pressure trend value calculated by Cumulus?

Thanks in advance.
Simon, WessexWeather
Image

User avatar
steve
Cumulus Author
Posts: 26714
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Cumulus PHP-GD Avatar

Post by steve » Fri 07 Jun 2013 4:56 pm

SpireWeather wrote:1. The pressure trend as it stands is a bit meaningless to a lay person. How could this be translated to text like the #pressuretrend tag?
See beteljuice's post in this thread: http://sandaysoft.com/forum/viewtopic.php?f=4&t=4383 (for the banner, but the principle is the same).
2. Over what period is the pressure trend value calculated by Cumulus?
Three hours (but supplied as an hourly rate).
Steve

User avatar
beteljuice
Posts: 2510
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: XP SP3 - honest
Location: Dudley, West Midlands, UK

Re: Cumulus PHP-GD Avatar

Post by beteljuice » Fri 07 Jun 2013 6:17 pm

RE. your avatar.

I made things the size and position they were for a reason.

Consider the case when you have minus temps, what will your display look like then ;)
Image
......................Imagine, what you will KNOW tomorrow !

User avatar
SpireWeather
Posts: 58
Joined: Fri 17 Jun 2011 7:43 pm
Weather Station: Davis Vantage Vue
Operating System: Windows XP SP3
Location: Wimborne Minster UK
Contact:

Re: Cumulus PHP-GD Avatar

Post by SpireWeather » Fri 07 Jun 2013 7:28 pm

Good point, I'll keep an eye on that.

Steve provided a link above to some code you'd written to add a pressure trend name. Where would I paste this into the avatar php file?

Apologies for all the questions but this is all new to me!
Simon, WessexWeather
Image

User avatar
beteljuice
Posts: 2510
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: XP SP3 - honest
Location: Dudley, West Midlands, UK

Re: Cumulus PHP-GD Avatar

Post by beteljuice » Fri 07 Jun 2013 10:36 pm

Code: Select all

// **** NEW
// Print Baro Trend Left

$text = $DATA[18];
$weather_trend = $text * 3;
if ($weather_trend >= 6.0)
  $pressure_trend_text = "Rising Rapidly";
elseif ($weather_trend > 3.5)
  $pressure_trend_text = "Rising Quickly";
elseif ($weather_trend > 1.5)
  $pressure_trend_text = "Rising";
else if ($weather_trend > 0.1)
  $pressure_trend_text = "Rising Slowly";
elseif ($weather_trend > -0.1)
  $pressure_trend_text = "Steady";
elseif ($weather_trend > -1.5)
  $pressure_trend_text = "Falling Slowly";
elseif ($weather_trend > -3.5)
  $pressure_trend_text = "Falling";
elseif ($weather_trend > -6.0)
  $pressure_trend_text = "Falling Quickly";
else
  $pressure_trend_text = "Falling Rapidly";

if ($SITE['usettf'] == "yes" ) {
    $size = 10;
    imagettftextbox($im, $size, 0, 140, 143, $white, $font3, $pressure_trend_text, 240, "left");    
}
Image
......................Imagine, what you will KNOW tomorrow !

User avatar
SpireWeather
Posts: 58
Joined: Fri 17 Jun 2011 7:43 pm
Weather Station: Davis Vantage Vue
Operating System: Windows XP SP3
Location: Wimborne Minster UK
Contact:

Re: Cumulus PHP-GD Avatar

Post by SpireWeather » Sat 08 Jun 2013 10:29 am

Thanks once again for your help beteljuice. It's all starting to make sense now.
Simon, WessexWeather
Image

weatherfrog80
Posts: 70
Joined: Tue 06 Mar 2012 7:50 pm
Weather Station: WH 1080
Operating System: Windows XP SP 3
Location: Bremerhaven, NW Germany
Contact:

Re: Cumulus PHP-GD Avatar

Post by weatherfrog80 » Sun 21 Jul 2013 11:22 am

phtvs wrote:Hi,

I had this problem that most sites wont accept a .php file as avatar.

So I inserted this lines into the code:

Code: Select all

$dest = "avatar.gif";
imagegif($im,$dest);
$filename = $dest;
Put this code in the avatar script before the lines:

Code: Select all

// We be done... destroy the image
imagedestroy($im);

exit;
This save the avatar to your server disk as avatar.gif
Now you can use the avatar.gif instead of avatar.php.
http://www.linktoyoursite/xxxx/avatar.gif
(Change xxx to the location of your avatar script)

Make use of the fantastic Cumulus toolbox to execute the avatar script once an hour.
So now you have an avatar.gif with fresh data on it every hour!!!!

It also is possible to make use of cronjob to refrsh the data on the avatar more often!

Of course this also works for the banner.php script ;-)

Sorry for the bad english...
Hi Theo,

I've been going through the steps and it works so far as saving the avatar.php file to an avatar.gif file.
I modified the avatar size settings so that it has now become a kind of larger mini display showing all current important values from my station. People using the software "WsWin" before might have an idea how
it would look like.
However i have a problem.
Right now the avatar.gif only updates when i execute the avatar.php by myself, but what settings in
Cumulus toolbox do i need, so that the avatar.gif is being updated automatically every 10 minutes for example?

Best Regards

Georg
Best Regards

Georg

Private weatherstation Bremerhaven-Twischkamp
Image

User avatar
steve
Cumulus Author
Posts: 26714
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Cumulus PHP-GD Avatar

Post by steve » Sun 21 Jul 2013 11:31 am

weatherfrog80 wrote:Right now the avatar.gif only updates when i execute the avatar.php by myself, but what settings in
Cumulus toolbox do i need, so that the avatar.gif is being updated automatically every 10 minutes for example?
In 'Setup' select the 'Remote Commands' tab and click 'Add'. Make sure 'HTTP address' is selected in the drop down, and put the address of your PHP file in the box after the 'http://'. Select 'hourly' from the 'Frequency' drop down, and click 'Save' (optionally doing a test first by clicking 'execute now').
Steve

Post Reply