Please read the posts in the Announcements section about the current status of Cumulus development now that I have retired

Please read this post before posting

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

Cumulus PHP-GD Banner

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

Moderators: daj, TNETWeather

kapo
Posts: 246
Joined: Thu Jan 03, 2013 1:59 pm
Weather Station: Davis VP2
Operating System: Windows 10
Location: Vihtavuori, Laukaa, Finland

Re: Cumulus PHP-GD Banner

Postby kapo » Thu Jan 24, 2013 8:58 pm

water01 wrote:You can use the standard colours in the banner.php file here

Code: Select all

$background_color   = imagecolorallocate($im, 0xC1, 0xFF, 0xC1);
$black              = imagecolorallocate($im, 0x00, 0x00, 0x00);
$green              = imagecolorallocate($im, 0x00, 0x80, 0x00);
$blue               = imagecolorallocate($im, 0x00, 0x00, 0x99);
$red                = imagecolorallocate($im, 0xff, 0x00, 0x00);
$indianred          = imagecolorallocate($im, 0x8b, 0x3a, 0x3a);
$white              = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);


The white line is one I added and you can add others using the same format and working out the hex RGB definition of the colour which is what the 3 items are after $im i.e. 0xFF, 0xFF, 0xFF.

To use the colour say in Temperature

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


If you are using TTF fonts and want white change

Code: Select all

    imagettftextbox($im, $size, 0, 0, 20, $red, $font1, $text, $SITE['image_width'], "center");


to

Code: Select all

    imagettftextbox($im, $size, 0, 0, 20, $white, $font1, $text, $SITE['image_width'], "center");


or if you are using the default font change

Code: Select all

imageWriteString($im, $size, $text, $red, "center", 23);


to

Code: Select all

imageWriteString($im, $size, $text, $white, "center", 23);


Thanks!
These are very usefull... But how can I have temperature font to : red, bold and a little bigger font, so that it`s easier to read from banner?

water01
Posts: 1449
Joined: Sat Aug 13, 2011 9:33 am
Weather Station: WH1081
Operating System: Windows 7 64bit HP SP1
Location: Somewhere in the USA
Contact:

Re: Cumulus PHP-GD Banner

Postby water01 » Thu Jan 24, 2013 9:16 pm

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

kapo
Posts: 246
Joined: Thu Jan 03, 2013 1:59 pm
Weather Station: Davis VP2
Operating System: Windows 10
Location: Vihtavuori, Laukaa, Finland

Re: Cumulus PHP-GD Banner

Postby kapo » Thu Jan 24, 2013 10:13 pm

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: 1449
Joined: Sat Aug 13, 2011 9:33 am
Weather Station: WH1081
Operating System: Windows 7 64bit HP SP1
Location: Somewhere in the USA
Contact:

Re: Cumulus PHP-GD Banner

Postby water01 » Thu Jan 24, 2013 11:34 pm

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!

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

Re: Cumulus PHP-GD Banner

Postby beteljuice » Thu Jan 24, 2013 11:35 pm

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 Jan 03, 2013 1:59 pm
Weather Station: Davis VP2
Operating System: Windows 10
Location: Vihtavuori, Laukaa, Finland

Re: Cumulus PHP-GD Banner

Postby kapo » Fri Jan 25, 2013 9:32 am

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: 54
Joined: Thu Aug 23, 2012 8:53 pm
Weather Station: WH 2080
Operating System: Windows 7
Location: Konin, Poland

Re: Cumulus PHP-GD Banner

Postby Mark14 » Fri Jan 25, 2013 10:20 am

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?

water01
Posts: 1449
Joined: Sat Aug 13, 2011 9:33 am
Weather Station: WH1081
Operating System: Windows 7 64bit HP SP1
Location: Somewhere in the USA
Contact:

Re: Cumulus PHP-GD Banner

Postby water01 » Fri Jan 25, 2013 11:43 am

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.

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

Re: Cumulus PHP-GD Banner

Postby steve » Fri Jan 25, 2013 11:46 am

But the script already has access to the data, via the realtime.txt file. Why would it need the php webtags?
Steve
-----
Hosting available for Cumulus web sites. See http://sandaysoft.com/forum/viewtopic.php?f=2&t=11876

Please read the posts in the Announcements section about the current status of Cumulus development since I have retired from my day job

water01
Posts: 1449
Joined: Sat Aug 13, 2011 9:33 am
Weather Station: WH1081
Operating System: Windows 7 64bit HP SP1
Location: Somewhere in the USA
Contact:

Re: Cumulus PHP-GD Banner

Postby water01 » Fri Jan 25, 2013 11:55 am

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.

Karv
Posts: 38
Joined: Sun Dec 16, 2012 11:19 pm
Weather Station: WH-1080
Operating System: Windows XP / 7, Ubuntu, Centos
Location: South Gloucestershire
Contact:

Re: Cumulus PHP-GD Banner

Postby Karv » Fri Jan 25, 2013 1:03 pm

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
Image

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

Re: Cumulus PHP-GD Banner

Postby beteljuice » Fri Jan 25, 2013 2:21 pm

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 Jan 26, 2013 1:09 pm, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !

Karv
Posts: 38
Joined: Sun Dec 16, 2012 11:19 pm
Weather Station: WH-1080
Operating System: Windows XP / 7, Ubuntu, Centos
Location: South Gloucestershire
Contact:

Re: Cumulus PHP-GD Banner

Postby Karv » Fri Jan 25, 2013 2:45 pm

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 :)
Image

Karv
Posts: 38
Joined: Sun Dec 16, 2012 11:19 pm
Weather Station: WH-1080
Operating System: Windows XP / 7, Ubuntu, Centos
Location: South Gloucestershire
Contact:

Re: Cumulus PHP-GD Banner

Postby Karv » Fri Jan 25, 2013 7:16 pm

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.
Image

Mark14
Posts: 54
Joined: Thu Aug 23, 2012 8:53 pm
Weather Station: WH 2080
Operating System: Windows 7
Location: Konin, Poland

Re: Cumulus PHP-GD Banner

Postby Mark14 » Sat Jan 26, 2013 11:11 am

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;


Return to “Web site - General”

Who is online

Users browsing this forum: No registered users and 3 guests