Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4018) - 28 March 2024

Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

Cumulus PHP-GD Banner

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

Moderator: daj

water01
Posts: 3215
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10 64bit
Location: Burnham-on-Sea
Contact:

Re: Cumulus PHP-GD Banner

Post by water01 »

Code: Select all

// Print Temp
$text = ret_value("temp") . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 18;
    imagettftextbox($im, $size, 0, 0, 20, $red, $font1, $text, $SITE['image_width'], "center");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $red, "center", 23);
}
The colour is red by default

Code: Select all

 $red
and the size is set by

Code: Select all

    $size = 18;
for TTF fonts and

Code: Select all

    $size = 5;
for the default fonts.

The TTF fonts are defined here

Code: Select all

$font1 = $SITE['fontdir'] . "arialbd.ttf";
$font2 = $SITE['fontdir'] . "arial.ttf";
$font3 = $SITE['fontdir'] . "verdana.ttf";
and again $font1 is Arial bold. I have verdana bold in my font directory but to use it you will have to add something like

Code: Select all

$font4 = $SITE['fontdir'] . "verdanab.ttf";
and change this line to

Code: Select all

 imagettftextbox($im, $size, 0, 0, 20, $red, $font4, $text, $SITE['image_width'], "center");
David
Image
kapo
Posts: 246
Joined: Thu 03 Jan 2013 1:59 pm
Weather Station: Davis VP2
Operating System: Windows 10
Location: Vihtavuori, Laukaa, Finland

Re: Cumulus PHP-GD Banner

Post by kapo »

water01 wrote:

Code: Select all

// Print Temp
$text = ret_value("temp") . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 18;
    imagettftextbox($im, $size, 0, 0, 20, $red, $font1, $text, $SITE['image_width'], "center");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $red, "center", 23);
}
The colour is red by default

Code: Select all

 $red
and the size is set by

Code: Select all

    $size = 18;
for TTF fonts and

Code: Select all

    $size = 5;
for the default fonts.

The TTF fonts are defined here

Code: Select all

$font1 = $SITE['fontdir'] . "arialbd.ttf";
$font2 = $SITE['fontdir'] . "arial.ttf";
$font3 = $SITE['fontdir'] . "verdana.ttf";
and again $font1 is Arial bold. I have verdana bold in my font directory but to use it you will have to add something like

Code: Select all

$font4 = $SITE['fontdir'] . "verdanab.ttf";
and change this line to

Code: Select all

 imagettftextbox($im, $size, 0, 0, 20, $red, $font4, $text, $SITE['image_width'], "center");
Yes, but for some ununderstable reason I can`t get ttf fonts to work.. My servers php does accept ttfonts, but i can`t get them work.. So I use default fonts, and that`s the reason of question of fontsize and fontbold.. And I do have noticed that temp. font is red... :geek: :mrgreen: :oops:
water01
Posts: 3215
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10 64bit
Location: Burnham-on-Sea
Contact:

Re: Cumulus PHP-GD Banner

Post by water01 »

Have you got the fonts directory with your TTF fonts in the same directory as where your banner resides.

e.g. if your banner code is at /htdocs/weather/banner.php

then fonts would be in

/htdocs/weather/fonts/

and your parameter in banner.php would read

Code: Select all

$SITE['fontdir']        = "fonts/";     # must contain ttf font files! 
David
Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Cumulus PHP-GD Banner

Post by beteljuice »

As far as I can tell you have not uploaded any fonts to your webspace.
Image
......................Imagine, what you will KNOW tomorrow !
kapo
Posts: 246
Joined: Thu 03 Jan 2013 1:59 pm
Weather Station: Davis VP2
Operating System: Windows 10
Location: Vihtavuori, Laukaa, Finland

Re: Cumulus PHP-GD Banner

Post by kapo »

O.k. Now the fonts are working.. I don` know what I did, but thank You everyone for help, anyway :P This is great forum, I have had help everytime I`ve asked... Next question I`ll ask is about my house renovation... :lol: :lol: :idea: :arrow: I suppose I`l have help for it too... :bash: :clap:
Mark14
Posts: 79
Joined: Thu 23 Aug 2012 8:53 pm
Weather Station: Ecowitt HP3501
Operating System: Windows 10
Location: Konin, Poland

Re: Cumulus PHP-GD Banner

Post by Mark14 »

I would like to have in my weather banner temperature values in different colours depended on the range. For example, when outside it's below 0*C (it's about 20*F) the temperature value is navy, when temperature is above 0*C the prints are purple or dark red. Is there the script ensures such a possibility?
Image
water01
Posts: 3215
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10 64bit
Location: Burnham-on-Sea
Contact:

Re: Cumulus PHP-GD Banner

Post by water01 »

This can be done as the banner code is written in PHP.

You would have to make Cumulus upload the php webtags, and add the include/require for them in the banner header,

Code: Select all

<?php require "./cumuluswebtags.php";?>
and then write some code to check $temp for your temperature ranges and set the colour accordingly.
David
Image
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Cumulus PHP-GD Banner

Post by steve »

But the script already has access to the data, via the realtime.txt file. Why would it need the php webtags?
Steve
water01
Posts: 3215
Joined: Sat 13 Aug 2011 9:33 am
Weather Station: Ecowitt HP2551
Operating System: Windows 10 64bit
Location: Burnham-on-Sea
Contact:

Re: Cumulus PHP-GD Banner

Post by water01 »

Sorry Steve, was just sitting here thinking that is really stupid answer realtime.txt is already mapped in the code!!! :bash:

As Steve says ignore the bit about the Cumulus php webtags (I wasn't thinking straight!!), just add the code to check $temp and output the colours you require.
David
Image
Karv
Posts: 40
Joined: Sun 16 Dec 2012 11:19 pm
Weather Station: WH-1080
Operating System: Windows XP / 7, Ubuntu, Centos
Location: South Gloucestershire

Re: Cumulus PHP-GD Banner

Post by Karv »

if you want to rip some colour coding from mine, feel free...

http://virtualkev.com/eq/weather2.jpeg?view=src

I've used the varaible $OUT_TEMP and checked the values in 2 degree steps (C) , and return the value in $colour which is then used in the image text line.

Code: Select all

        if ($OUT_TEMP < -10)
        {
            $colour = imagecolorallocate($image,  50,   0, 127); // -12
        }
        elseif ($OUT_TEMP < -8 && $OUT_TEMP > -10)
        {
            $colour = imagecolorallocate($image,   0,   0, 130);
        }
        elseif ($OUT_TEMP < -6 && $OUT_TEMP > -8)
        {
            $colour = imagecolorallocate($image,   0,  51, 180);
        }
        elseif ($OUT_TEMP < -4 && $OUT_TEMP > -6)
        {
            $colour = imagecolorallocate($image,   0,   0, 255);
        }
        elseif ($OUT_TEMP < -2 && $OUT_TEMP > -4)
        {
            $colour = imagecolorallocate($image,   0, 126, 255);
        }
        elseif ($OUT_TEMP < 0 && $OUT_TEMP > -2)
        {
            $colour = imagecolorallocate($image,   0, 190, 255);
        }
        elseif ($OUT_TEMP >= 0 && $OUT_TEMP <= 2)
        {
            $colour = imagecolorallocate($image,   0, 255, 255); //   0
        }
        elseif ($OUT_TEMP >= 2 && $OUT_TEMP <= 4)
        {
            $colour = imagecolorallocate($image,   0, 147, 198);
        }
        elseif ($OUT_TEMP >= 4 && $OUT_TEMP <= 6)
        {
            $colour = imagecolorallocate($image,  24, 215, 140);
        }
        elseif ($OUT_TEMP >= 6 && $OUT_TEMP <= 8)
        {
            $colour = imagecolorallocate($image,   0, 170, 100);
        }
        elseif ($OUT_TEMP >= 8 && $OUT_TEMP <= 10)
        {
            $colour = imagecolorallocate($image,  43, 170,  43);
        }
        elseif ($OUT_TEMP >= 10 && $OUT_TEMP <= 12)
        {
            $colour = imagecolorallocate($image,  43, 200,  43);
        }
        elseif ($OUT_TEMP >= 12 && $OUT_TEMP <= 14)
        {
            $colour = imagecolorallocate($image,   0, 255,   0);
        }
        elseif ($OUT_TEMP >= 14 && $OUT_TEMP <= 16)
        {
            $colour = imagecolorallocate($image, 204, 255,   0);
        }
        elseif ($OUT_TEMP >= 16 && $OUT_TEMP <= 18)
        {
            $colour = imagecolorallocate($image, 255, 255,   0);
        }
        elseif ($OUT_TEMP >= 18 && $OUT_TEMP <= 20)
        {
            $colour = imagecolorallocate($image, 237, 237, 136);
        }
        elseif ($OUT_TEMP >= 20 && $OUT_TEMP <= 22)
        {
            $colour = imagecolorallocate($image, 228, 204, 102);
        }
        elseif ($OUT_TEMP >= 22 && $OUT_TEMP <= 24)
        {
            $colour = imagecolorallocate($image, 220, 174,  73);
        }
        elseif ($OUT_TEMP >= 24 && $OUT_TEMP <= 26)
        {
            $colour = imagecolorallocate($image, 255, 170,   0);
        }
        elseif ($OUT_TEMP >= 26 && $OUT_TEMP <= 28)
        {
            $colour = imagecolorallocate($image, 255,  85,   0);
        }
        elseif ($OUT_TEMP >= 28 && $OUT_TEMP <= 30)
        {
            $colour = imagecolorallocate($image, 255,   0,   0);
        }
        elseif ($OUT_TEMP >= 30 && $OUT_TEMP <= 32)
        {
            $colour = imagecolorallocate($image, 200,   0,   0);
        }
        elseif ($OUT_TEMP >= 32 && $OUT_TEMP <= 34)
        {
            $colour = imagecolorallocate($image, 173,   0,   0);
        }
        elseif ($OUT_TEMP >= 34 && $OUT_TEMP <= 36)
        {
            $colour = imagecolorallocate($image, 147,   0,   0);
        }
        elseif ($OUT_TEMP > 36)
        {
            $colour = imagecolorallocate($image, 120,   0,   0); // +36
        }
Kev
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Cumulus PHP-GD Banner

Post by beteljuice »

NB: Those are karvs own variable names !

In the script "as delivered" you need to change in the above:

$OUT_TEMP becomes $temp

and

$image becomes $im
Last edited by beteljuice on Sat 26 Jan 2013 1:09 pm, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !
Karv
Posts: 40
Joined: Sun 16 Dec 2012 11:19 pm
Weather Station: WH-1080
Operating System: Windows XP / 7, Ubuntu, Centos
Location: South Gloucestershire

Re: Cumulus PHP-GD Banner

Post by Karv »

Yes, maybe I should have made that clear, mine is a completely independant script (written before I found this one existed)... so another good idea is to use the forum search facility :)
Karv
Posts: 40
Joined: Sun 16 Dec 2012 11:19 pm
Weather Station: WH-1080
Operating System: Windows XP / 7, Ubuntu, Centos
Location: South Gloucestershire

Re: Cumulus PHP-GD Banner

Post by Karv »

While waiting for 'er indoors to get ready to go to the pub, I bug fixed mine slightly and created a funtion for colours and sorted Mark14's too.


Mark - enjoy, don't forget to backup your current one just in case I broke this.
mark.txt
** edited, found a rogue colour
You do not have the required permissions to view the files attached to this post.
Mark14
Posts: 79
Joined: Thu 23 Aug 2012 8:53 pm
Weather Station: Ecowitt HP3501
Operating System: Windows 10
Location: Konin, Poland

Re: Cumulus PHP-GD Banner

Post by Mark14 »

I knew that it must be a simple script, but I wanted to save time and so I asked whether someone has already written a script.

Karv, thanks a lot for your help and for entering the code into my banner. It works. I changed some colors in order to the temperature would be more visible. By the way, I extended temperature scale - yesterday my weather station beat record for the lowest temperature, for a while it was -16*C (3.2*F). This rarely happens. In my region, Greater Poland, in January normal temperature is close to 0*C (32*F).

I attached my palette of colors. Maybe someone will like it and use :)

Code: Select all

function TEMP_COLOUR($T)
{
	if ($T < -15)
	{
		$rgb = array("153","0","102"); // -16
	}
	elseif ($T < -10 && $T >= -15)
	{
		$rgb = array("50","0","127");
	}
	elseif ($T < -8 && $T >= -10)
	{
		$rgb = array("0","0","51");
	}
	elseif ($T < -6 && $T >= -8)
	{
		$rgb = array("0","0","102");
	}
	elseif ($T < -4 && $T >= -6)
	{
		$rgb = array("0","0","153");
	}
	elseif ($T < -2 && $T >= -4)
	{
		$rgb = array("0","0","24");
	}
	elseif ($T < 0 && $T >= -2)
	{
		$rgb = array("0","0","255");
	}
	elseif ($T >= 0 && $T <= 2)
	{
		$rgb = array("0","64","128"); //   0
	}
	elseif ($T >= 2 && $T <= 4)
	{
		$rgb = array("0","128","128");
	}
	elseif ($T >= 4 && $T <= 6)
	{
		$rgb = array("0","64","64");
	}
	elseif ($T >= 6 && $T <= 8)
	{
		$rgb = array("0","128","64");
	}
	elseif ($T >= 8 && $T <= 10)
	{
		$rgb = array("0","128","128");
	}
	elseif ($T >= 10 && $T <= 12)
	{
		$rgb = array("0","64","0");
	}
	elseif ($T >= 12 && $T <= 14)
	{
		$rgb = array("0","85","0");
	}
	elseif ($T >= 14 && $T <= 16)
	{
		$rgb = array("0","128","0");
	}
	elseif ($T >= 16 && $T <= 18)
	{
		$rgb = array("0","179","0");
	}
	elseif ($T >= 18 && $T <= 20)
	{
		$rgb = array("105","210","0");
	}
	elseif ($T >= 20 && $T <= 22)
	{
		$rgb = array("213","213","0");
	}
	elseif ($T >= 22 && $T <= 24)
	{
		$rgb = array("221","111","0");
	}
	elseif ($T >= 24 && $T <= 26)
	{
		$rgb = array("236","77","0");
	}
	elseif ($T >= 26 && $T <= 28)
	{
		$rgb = array("255","40","40");
	}
	elseif ($T >= 28 && $T <= 30)
	{
		$rgb = array("236","0","0");
	}
	elseif ($T >= 30 && $T <= 32)
	{
		$rgb = array("173","0","0");
	}
	elseif ($T >= 32 && $T <= 34)
	{
		$rgb = array("120","0","0");
	}
	elseif ($T >= 34 && $T <= 36)
	{
		$rgb = array("128","0","64");
	}
	elseif ($T > 36)
	{
		$rgb = array("64","0","64"); // +36
	}
	return $rgb;
Image
User avatar
William Grimsley
Posts: 833
Joined: Thu 22 Sep 2011 5:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 7 Home Premium 64-bit
Location: Latitude: 50.70189285 Longitude: -3.30849957
Contact:

Re: Cumulus PHP-GD Banner

Post by William Grimsley »

Hi there,

Ok, first of all I've got these 2 bits of code in my banner.php:

As you can see, I've deleted the "wspeed" tag and added the "wlatest" tag. I thought this makes sense.

Code: Select all

// Current field names (matches tag fields) used
$SITE['cvalues'] = array(
    "date","time","temp","hum","dew","wlatest","wgust","avgbearing","rrate",
    "rfall","press","wdir","beaufort","windunit","tempunit","pressunit","rainunit",
    "windrun","presstrend","rmonth","ryear","rfallY","intemp","inhum","wchill",
    "temptrendval","tempTH","TtempTH","tempTL","TtempTL",
    "windTM","TwindTM","wgustTM","TwgustTM",
    "pressTH","TpressTH","pressTL","TpressTL",
    "cversion","cbuild");
Then, I added the same thing here. I changed the ("wspeed") tag to the ("wlatest") tag. I thought this makes sense.

Code: Select all

// Print windspeed
$text = "Wind: " . ret_value("wdir") . " " . ret_value("wlatest") . ' ' . ret_value("windunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 10;
    imagettftextbox($im, $size, 0, 0, 22, $green, $font1, $text, $SITE['image_width'], "left");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $green, "left", 23);
}
But, then it just came up with the "wspeed" value instead of the "wlatest" value on my banner.php file. :(

Why has this happened?

Thanks

William
Post Reply