Page 3 of 4

Re: Cumulus PHP-GD Avatar

Posted: Tue 04 Jun 2013 9:46 pm
by mcrossley
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']);
}

Re: Cumulus PHP-GD Avatar

Posted: Tue 04 Jun 2013 10:18 pm
by SpireWeather
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.

Re: Cumulus PHP-GD Avatar

Posted: Tue 04 Jun 2013 10:36 pm
by beteljuice
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:

Re: Cumulus PHP-GD Avatar

Posted: Wed 05 Jun 2013 5:27 am
by SpireWeather
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,

Re: Cumulus PHP-GD Avatar

Posted: Wed 05 Jun 2013 8:38 am
by CrasHBoneS
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']"

Re: Cumulus PHP-GD Avatar

Posted: Wed 05 Jun 2013 10:28 am
by beteljuice
@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

Re: Cumulus PHP-GD Avatar

Posted: Wed 05 Jun 2013 11:04 am
by SpireWeather
Yes Beteljuice, I will be downloading the zip this evening after work.

Thanks again,

Re: Cumulus PHP-GD Avatar

Posted: Fri 07 Jun 2013 4:18 pm
by SpireWeather
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.

Re: Cumulus PHP-GD Avatar

Posted: Fri 07 Jun 2013 4:56 pm
by steve
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: https://cumulus.hosiene.co.uk/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).

Re: Cumulus PHP-GD Avatar

Posted: Fri 07 Jun 2013 6:17 pm
by beteljuice
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 ;)

Re: Cumulus PHP-GD Avatar

Posted: Fri 07 Jun 2013 7:28 pm
by SpireWeather
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!

Re: Cumulus PHP-GD Avatar

Posted: Fri 07 Jun 2013 10:36 pm
by beteljuice

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");    
}

Re: Cumulus PHP-GD Avatar

Posted: Sat 08 Jun 2013 10:29 am
by SpireWeather
Thanks once again for your help beteljuice. It's all starting to make sense now.

Re: Cumulus PHP-GD Avatar

Posted: Sun 21 Jul 2013 11:22 am
by weatherfrog80
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

Re: Cumulus PHP-GD Avatar

Posted: Sun 21 Jul 2013 11:31 am
by steve
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').