Welcome to the Cumulus Support forum.

Latest Cumulus MX release 3.6.10 (build 3086) - 24 June 2020 (please see important announcement regarding releases since 3.5.0)
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 the NOAA report and Snow Index drop-down menus to 2030)

See the Wiki to download the software or click on the Downloads link in the Forum Banner.

Cumulus PHP-GD Banner

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

Moderator: daj

forestedge
Posts: 61
Joined: Sun 29 Jul 2012 11:46 am
Weather Station: Davis Vantage Pro2 Plus FARS
Operating System: Windows 10 64 bit
Location: Ashurst Bridge, Hampshire UK
Contact:

Re: Cumulus PHP-GD Banner

Post by forestedge »

I finally managed to get most background images to work if they had a JPG suffix when jpg or png did not! The size of the image seemed irrelevant.

http://www.tottonweather.co.uk/banner.php
Could it be that the image file name has a leading dot (.)?
Removing the dot also helped thanks.

User avatar
nitrx
Posts: 1297
Joined: Sun 13 Dec 2009 1:21 pm
Weather Station: WH1080
Operating System: Windows 10
Location: Apeldoorn The Netherlands
Contact:

Re: Cumulus PHP-GD Banner

Post by nitrx »

As said many times don t use the name banner its mostly blocked by adblockers.

Phil23
Posts: 496
Joined: Sat 16 Jul 2016 11:59 pm
Weather Station: Davis Vantage Pro2 Plus
Operating System: Win7 Pro
Location: Australia

Re: Cumulus PHP-GD Banner

Post by Phil23 »

beteljuice wrote:
Thu 05 Dec 2019 11:00 pm
cross posted !!!

Like many others your banner version does not look for the later fields that have been added to realtime.txt.
Presume mine is the same as I see this in the file.

Code: Select all

############################################################################
# Reference: Cumulus Format of realtime.txt file
############################################################################
#   Field       Pos     Example     Description
#   date        0       18/10/08    date (always dd/mm/yy)
#   time        1       16:03:45    time (always hh:mm:ss)
#   temp        2       8.4         outside temperature
#   hum         3       84          relative humidity
#   dew         4       5.8         dewpoint
#   wspeed      5       24.2        wind speed (average)
#   wgust       6       33.0        wind speed (gust)
#   avgbearing  7       261         wind bearing
#   rrate       8       0.0         current rain rate
#   rfall       9       1.0         rain today
#   press       10      999.7       barometer
#   wdir        11      W           wind direction
#   beaufort    12      6           wind speed (beaufort)
#   windunit    13      mph         wind units
#   tempunit    14      C           temperature units
#   pressunit   15      mb          pressure units
#   rainunit    16      mm          rain units
#   windrun     17      146.6       wind run (today)
#   pressrend   18      +0.1        pressure trend value
#   rmonth      19      85.2        monthly rain
#   ryear       20      588.4       yearly rain
#   rfallY      21      11.6        yesterday's rainfall
#   intemp      22      20.3        inside temperature
#   inhum       23      57          inside humidity
#   wchll       24      3.6         wind chill
#   temptrendval 25     -0.7        temperature trend value
#   tempTH      26      10.9        today's high temp
#   TtempTH     27      12:00       time of today's high temp (hh:mm)
#   tempTL      28      7.8         today's low temp
#   TtempTL     29      14:41       time of today's low temp (hh:mm)
#   windTM      30      37.4        today's high wind speed (average)
#   TwindTM     31      14:38       time of today's hi wind (avg) (hh:mm)
#   wgustTM     32      44.0        today's high wind gust
#   TwgustTM    33      14:28       time of today's high wind gust (hh:mm)
#   pressTH     34      999.8       today's high pressure
#   TpressTH    35      16:01       time of today's high pressure (hh:mm)
#   pressTL     36      998.4       today's low pressure
#   TpressTL    37      12:06       time of today's low pressure (hh:mm)
#   cversion    38      1.8.2       Cumulus version
#   cbuild      39      459         Cumulus build no
############################################################################

Can someone post either a link or the file of an up to date Generic version.

I'd like to update mine & also place the source on a page in the Wiki to help others find it easily in the future.

Thanks

Phil.

User avatar
beteljuice
Posts: 2950
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: Cumulus PHP-GD Banner

Post by beteljuice »

I thought my post explained everything and the realtime.txt fields are already in the wiki.

Whatever ....

You can follow the existing logic and use $SITE['cvalues'] ... OR you could simply refer to the array $DATA[#field number]

New set of $SITE['cvalues']

Code: Select all

// Current field names (matches tag fields) used
$SITE['cvalues'] = array(
    "date","time","temp","hum","dew","wspeed","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",
	"wgust","heatindex","humidex","UV","ET","SolarRad","avgbearing","rhour",
	"forecastnumber","isdaylight","SensorContactLost","wdir",
	"cloudbasevalue","cloudbaseunit","apptemp","SunshineHours",
	"CurrentSolarMax","IsSunny"
	);

New reference 'table':

Code: Select all


############################################################################
# Reference: Cumulus Format of realtime.txt file
############################################################################
#   Field       Pos     Example     Description
#   date        0       18/10/08    date (always dd/mm/yy)
#   time        1       16:03:45    time (always hh:mm:ss)
#   temp        2       8.4         outside temperature
#   hum         3       84          relative humidity
#   dew         4       5.8         dewpoint
#   wspeed      5       24.2        wind speed (average)
#   wgust       6       33.0        wind speed (gust)
#   avgbearing  7       261         wind bearing
#   rrate       8       0.0         current rain rate
#   rfall       9       1.0         rain today
#   press       10      999.7       barometer
#   wdir        11      W           wind direction
#   beaufort    12      6           wind speed (beaufort)
#   windunit    13      mph         wind units
#   tempunit    14      C           temperature units
#   pressunit   15      mb          pressure units
#   rainunit    16      mm          rain units
#   windrun     17      146.6       wind run (today)
#   pressrend   18      +0.1        pressure trend value
#   rmonth      19      85.2        monthly rain
#   ryear       20      588.4       yearly rain
#   rfallY      21      11.6        yesterday's rainfall
#   intemp      22      20.3        inside temperature
#   inhum       23      57          inside humidity
#   wchll       24      3.6         wind chill
#   temptrendval 25     -0.7        temperature trend value
#   tempTH      26      10.9        today's high temp
#   TtempTH     27      12:00       time of today's high temp (hh:mm)
#   tempTL      28      7.8         today's low temp
#   TtempTL     29      14:41       time of today's low temp (hh:mm)
#   windTM      30      37.4        today's high wind speed (average)
#   TwindTM     31      14:38       time of today's hi wind (avg) (hh:mm)
#   wgustTM     32      44.0        today's high wind gust
#   TwgustTM    33      14:28       time of today's high wind gust (hh:mm)
#   pressTH     34      999.8       today's high pressure
#   TpressTH    35      16:01       time of today's high pressure (hh:mm)
#   pressTL     36      998.4       today's low pressure
#   TpressTL    37      12:06       time of today's low pressure (hh:mm)
#   cversion    38      1.8.2       Cumulus version
#   cbuild      39      459         Cumulus build no
// Later Additional fields
#   wgust       40      36.0        10-minute high gust <#wgust>
#   heatindex   41      10.3        Heat index <#heatindex>
#   humidex     42      10.5        Humidex <#humidex>
# 	UV          43      13          UV Index <#UV>
#   ET          44      0.2         evapotranspiration today <#ET>
#   SolarRad    45      14          solar radiation W/m2 <#SolarRad>
#   avgbearing  46      260         10-minute average wind bearing (degrees) <#avgbearing>
#   rhour       47      2.3         rainfall last hour <#rhour>
#   forecastnumber 48   3           The number of the current (Zambretti) forecast as per Strings.ini. <#forecastnumber>
#   isdaylight  49      1           Flag to indicate that the location of the station is currently in daylight (1 = yes, 0 = No) <#isdaylight>
#   SensorContactLost 50 1          If the station has lost contact with its remote sensors "Fine Offset only", a Flag number is given (1 = Yes, 0 = No) <#SensorContactLost>
#   wdir        51      NNW         Average wind direction <#wdir>
#   cloudbasevalue 52   2040        Cloud base <#cloudbasevalue>
#   cloudbaseunit 53    ft          Cloud base units <#cloudbaseunit>
#   apptemp     54      12.3        Apparent temperature <#apptemp>
#   SunshineHours 55    11.1        Sunshine hours so far today <#SunshineHours>
#   CurrentSolarMax 56  420.1       Current theoretical max solar radiation <#CurrentSolarMax>
#   IsSunny     57      1           Is it sunny? 1 if the sun is shining, otherwise 0 (above or below threshold) <#IsSunny>
############################################################################

Edit: link suffix corrected :oops:
and you can always view the source code of anybody's banner by .php?view=sce
Last edited by beteljuice on Mon 25 May 2020 1:26 am, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !

Phil23
Posts: 496
Joined: Sat 16 Jul 2016 11:59 pm
Weather Station: Davis Vantage Pro2 Plus
Operating System: Win7 Pro
Location: Australia

Re: Cumulus PHP-GD Banner

Post by Phil23 »

beteljuice wrote:
Sun 12 Jan 2020 10:33 pm
I thought my post explained everything and the realtime.txt fields are already in the wiki.
Thanks,

Just wanted to clarify before going on the wrong tangent.

Here's what I ended up with after changing the download that sits at https://saratoga-weather.org/scripts-le ... netweather

Let me know if there are any other changes that others use to make it more current.

Will try & add it to a Wiki page in the next few days if all looks Ok.

Code: Select all

<?php
############################################################################
# A Project of TNET Services, Inc.
############################################################################
#
#   Project:    Cumulus Project 
#   Package:    Cumulus Weather Banner
#   Module:     banner.php
#   Version:    3.1 - January 14th, 2020 (Unofficial).
#   Purpose:    Outputs a plain weather graphic based upon
#               the Cumulus realtime.txt file
#   Authors:    Kevin W. Reed <programs@tnet.com>
#               TNET Services, Inc.
#   Copyright:  (c) 1992-2008 Copyright TNET Services, Inc.
#
#   License:    
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
#   
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#   
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 
#   USA.
#
############################################################################
#   HISTORY
############################################################################
#
#   1.0 Released Oct 4th 2008 
#       Initial Release
#
#   1.1 Released Oct 5th 2008
#       Added TTF Support
#       Added Check for Rain and if none output No Rain Today
#
#   1.2 Released Oct 5th 2008
#       Corrected ISO Date format, was missing the 20 to make the year
#       a 4 digit value.  Realtime.txt data has it as a 2 digit year
#       value.
#
#   1.3 Released Oct 6th 2008
#       Added new field $SITE['dateiso']  If yes, the date is formated
#       in ISO format (YYYY-MM-DD), else it will use a worded month
#       Date (Oct 6 2008)
#
#   1.4 Released Oct 8th 2008
#       Increased the default size of the Cumulus Version Date line to
#       make it more readable. 
#
#   2.0 Released Oct 9th 2008
#       Reconfigured to use new write functions that provide right, left
#       center to position the text more accurately
#
#   3.0 Released Oct 19th, 2008
#       Reconfigured to use extended realtime.txt format that was
#       Released with Cumulus 1.8.2 Beta.
#   3.1 (Unofficial) Modified Jan 14th, 2020 to include additional fields present in CumulusMX
#       Edited by Phil23 at Cumulus Forum
#
############################################################################
#   This document uses Tab 4 Settings
############################################################################
$DATA   = array();
$SITE   = array();
############################################################################
# CONFIGURATION INFORMATION
############################################################################
$SITE['version']        = "3.0";
$SITE['hloc']           = "./";
$SITE['datafile']       = "realtime.txt";
$SITE['image_width']    = 468;
$SITE['image_height']   = 60;
#---------------------------------------------------------------------------
$SITE['fontdir']        = "fonts/";     # must contain ttf font files!
$SITE['usettf']         = "no";        # Set to No to use default fonts
#---------------------------------------------------------------------------
$SITE['format']         = "png";        # Options: jpeg  gif  png 
$SITE['dateiso']        = "no";
$SITE['sitename']       = "YOUR SITE NAME";
#---------------------------------------------------------------------------
// Current field names (matches tag fields) used
$SITE['cvalues'] = array(
    "date","time","temp","hum","dew","wspeed","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",
      "wgust","heatindex","humidex","UV","ET","SolarRad","avgbearing","rhour",
      "forecastnumber","isdaylight","SensorContactLost","wdir",
      "cloudbasevalue","cloudbaseunit","apptemp","SunshineHours",
      "CurrentSolarMax","IsSunny"
);
############################################################################

############################################################################
# SOURCECODE VIEW
############################################################################
if ( isset($_REQUEST['view']) && $_REQUEST['view'] == 'sce' ) {
    $filenameReal = __FILE__;
    $download_size = filesize($filenameReal);
    header('Pragma: public');
    header('Cache-Control: private');
    header('Cache-Control: no-cache, must-revalidate');
    header("Content-type: text/plain");
    header("Accept-Ranges: bytes");
    header("Content-Length: $download_size");
    header('Connection: close');
    readfile($filenameReal);
    exit;
}
############################################################################
# Reference: Cumulus Format of realtime.txt file
############################################################################
#   Field       Pos     Example     Description
#   date        0       18/10/08    date (always dd/mm/yy)
#   time        1       16:03:45    time (always hh:mm:ss)
#   temp        2       8.4         outside temperature
#   hum         3       84          relative humidity
#   dew         4       5.8         dewpoint
#   wspeed      5       24.2        wind speed (average)
#   wgust       6       33.0        wind speed (gust)
#   avgbearing  7       261         wind bearing
#   rrate       8       0.0         current rain rate
#   rfall       9       1.0         rain today
#   press       10      999.7       barometer
#   wdir        11      W           wind direction
#   beaufort    12      6           wind speed (beaufort)
#   windunit    13      mph         wind units
#   tempunit    14      C           temperature units
#   pressunit   15      mb          pressure units
#   rainunit    16      mm          rain units
#   windrun     17      146.6       wind run (today)
#   pressrend   18      +0.1        pressure trend value
#   rmonth      19      85.2        monthly rain
#   ryear       20      588.4       yearly rain
#   rfallY      21      11.6        yesterday's rainfall
#   intemp      22      20.3        inside temperature
#   inhum       23      57          inside humidity
#   wchll       24      3.6         wind chill
#   temptrendval 25     -0.7        temperature trend value
#   tempTH      26      10.9        today's high temp
#   TtempTH     27      12:00       time of today's high temp (hh:mm)
#   tempTL      28      7.8         today's low temp
#   TtempTL     29      14:41       time of today's low temp (hh:mm)
#   windTM      30      37.4        today's high wind speed (average)
#   TwindTM     31      14:38       time of today's hi wind (avg) (hh:mm)
#   wgustTM     32      44.0        today's high wind gust
#   TwgustTM    33      14:28       time of today's high wind gust (hh:mm)
#   pressTH     34      999.8       today's high pressure
#   TpressTH    35      16:01       time of today's high pressure (hh:mm)
#   pressTL     36      998.4       today's low pressure
#   TpressTL    37      12:06       time of today's low pressure (hh:mm)
#   cversion    38      1.8.2       Cumulus version
#   cbuild      39      459         Cumulus build no
// Later Additional fields
#   wgust       40      36.0        10-minute high gust <#wgust>
#   heatindex   41      10.3        Heat index <#heatindex>
#   humidex     42      10.5        Humidex <#humidex>
#   UV          43      13          UV Index <#UV>
#   ET          44      0.2         evapotranspiration today <#ET>
#   SolarRad    45      14          solar radiation W/m2 <#SolarRad>
#   avgbearing  46      260         10-minute average wind bearing (degrees) <#avgbearing>
#   rhour       47      2.3         rainfall last hour <#rhour>
#   forecastnumber 48   3           The number of the current (Zambretti) forecast as per Strings.ini. <#forecastnumber>
#   isdaylight  49      1           Flag to indicate that the location of the station is currently in daylight (1 = yes, 0 = No) <#isdaylight>
#   SensorContactLost 50 1          If the station has lost contact with its remote sensors "Fine Offset only", a Flag number is given (1 = Yes, 0 = No) <#SensorContactLost>
#   wdir        51      NNW         Average wind direction <#wdir>
#   cloudbasevalue 52   2040        Cloud base <#cloudbasevalue>
#   cloudbaseunit 53    ft          Cloud base units <#cloudbaseunit>
#   apptemp     54      12.3        Apparent temperature <#apptemp>
#   SunshineHours 55    11.1        Sunshine hours so far today <#SunshineHours>
#   CurrentSolarMax 56  420.1       Current theoretical max solar radiation <#CurrentSolarMax>
#   IsSunny     57      1           Is it sunny? 1 if the sun is shining, otherwise 0 (above or below threshold) <#IsSunny>
############################################################################


// Path to our font file
$font1 = $SITE['fontdir'] . "arialbd.ttf";
$font2 = $SITE['fontdir'] . "arial.ttf";
$font3 = $SITE['fontdir'] . "verdana.ttf";

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

$months = array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
    "Sep","Oct","Nov","Dec");

if ( $SITE['dateiso'] == "yes" ) {
    // Fix date to use ISO formatted date
    $DATA[0] = "20" . substr($DATA[0],6,2) . '-' . substr($DATA[0],3,2) . '-' . 
        substr($DATA[0],0,2);
} else {
    // Fix date to use Month formatted date
    $DATA[0] = $months[intval(substr($DATA[0],3,2)) -1 ] . 
        " " . intval(substr($DATA[0],0,2)) . " " .
        "20" . substr($DATA[0],6,2);
}

// Fix time by removing seconds from the field
$DATA[1] = substr($DATA[1],0,5);


// Output the header to let the browser know we are
// sending a graphic file format
header("Content-type: image/" . $SITE['format'] );
$im = @imagecreate($SITE['image_width'], $SITE['image_height'])
    or die("Cannot Initialize new GD image stream");
    
// Set colors we want to use...
// first background is a white background
$background_color   = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black              = imagecolorallocate($im, 0x00, 0x00, 0x00);
$green              = imagecolorallocate($im, 0x00, 0x80, 0x00);
$blue               = imagecolorallocate($im, 0x00, 0x00, 0xff);
$red                = imagecolorallocate($im, 0xff, 0x00, 0x00);

// Make a Border Around the box
ImageRectangle($im, 0, 0, $SITE['image_width'] -1 , 
    $SITE['image_height'] -1, $black);

// Print Station Name
$text = $SITE['sitename'];

if ($SITE['usettf'] == "yes" ) {
    $size = 11;
    imagettftextbox($im, $size, 0, 0, 4, $green, $font1, $text, $SITE['image_width'], "left");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $green, "left", 3);
}

// Print Date (top right corner)
$text = ret_value("date") . ' @ ' . ret_value("time");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 1, $green, $font3, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $green, "right", 1);
}


// Print Cumulus version info
$text = "Cumulus v" . ret_value("cversion") . ' #' . ret_value("cbuild");
if ($SITE['usettf'] == "yes" ) {
    $size = 6;
    imagettftextbox($im, $size, 0, 0, 14, $green, $font3, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $green, "right", 11);
}

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

// Print Humitidy and Dewpt Centered
$text = "Hum: " . ret_value("hum") . "% - " . "DewPt: " . ret_value("dew") . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 10;
    imagettftextbox($im, $size, 0, 0, 41, $black, $font2, $text, $SITE['image_width'], "center");
} else {
    $size = 3;
    imageWriteString($im, $size, $text, $black, "center", 40);
}

// Print windspeed
$text = "Wind: " . ret_value("wdir") . " @ " . ret_value("wspeed") . ret_value("windunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 10;
    imagettftextbox($im, $size, 0, 0, 22, $black, $font3, $text, $SITE['image_width'], "left");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $black, "left", 23);
}


// Print Wind gust
$text = "Gust: " . ret_value("wgust") . ret_value("windunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 40, $black, $font2, $text, $SITE['image_width'], "left");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $black, "left", 39);
}


// Print Rain
if (ret_value("rfall") == "0.00" ) {
    $text = "No Rain Today";
    $py = 22;
} else {
    $text = "   Rain: " . ret_value("rfall") . ' ' . ret_value("rainunit");
    $py = 25;
}
if ($SITE['usettf'] == "yes" ) {
    $size = 10;
    imagettftextbox($im, $size, 0, 0, $py, $blue, $font3, $text, $SITE['image_width'], "right");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $blue, "right", 23);
}


// Print Baro
$text = "Baro: " . ret_value("press") . ' ' . ret_value("pressunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 42, $black, $font2, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $black, "right", 39);
}


// Output the image in the format we are
// setup.

if ($SITE['format'] == "png" ) {
    imagepng($im);
}

if ($SITE['format'] == "jpeg" ) {
    imagejpeg($im); 
}

if ($SITE['format'] == "gif" ) {
    imagegif($im);  
}

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

exit;

############################################################################
# FUNCTIONS
############################################################################

// Function to read the data file with the
// Delimiter provided

function get_raw( $rawfile , $del ) {
    $rawdata = array();
    $fd = fopen( $rawfile, "r" );
    if ( $fd ) {
        $rawinfo = '';
        while (! feof ( $fd ) ) {
            $rawinfo .= fread( $fd, 8192 );
        }
        fclose($fd);
        $rawdata = explode ( $del, $rawinfo );
    } else {
        $rawdata[0]= -9999;
    }
    return $rawdata;
}


// function outputs a string centered in the image
function center_text ( $image, $size, $string, $y, $color) {
    $px = ((imagesx($image)/2) - ( ImageFontWidth($size) * 
    strlen($string) ) / 2);
    imagestring($image, $size, $px, $y,$string, $color);
}


// Function snarfed off of a PHP forum.  User sk89q

function imagettftextbox(&$image, $size, $angle, $left, $top, $color, 
    $font, $text, $max_width, $align)
{
        $text_lines = explode("\n", $text); // Supports line breaks!
       
        $lines = array();
        $line_widths = array();
       
        $largest_line_height = 0;
       
        foreach($text_lines as $block)
        {
            $current_line = ''; // Reset current line
           
            $words = explode(' ', $block); // Split the text array of single words
           
            $first_word = TRUE;
           
            $last_width = 0;
           
            for($i = 0; $i < count($words); $i++)
            {
                $item = $words[$i];
                $dimensions = imagettfbbox($size, $angle, $font, 
                    $current_line . ($first_word ? '' : ' ') . $item);
                $line_width = $dimensions[2] - $dimensions[0];
                $line_height = $dimensions[1] - $dimensions[7];
               
                if($line_height > $largest_line_height) 
                    $largest_line_height = $line_height;
               
                if($line_width > $max_width && !$first_word)
                {
                    $lines[] = $current_line;
                   
                    $line_widths[] = $last_width ? $last_width : $line_width;
                   
                    /*if($i == count($words))
                    {
                        continue;
                    }*/
                   
                    $current_line = $item;
                }
                else
                {
                    $current_line .= ($first_word ? '' : ' ') . $item;
                }
               
                if($i == count($words) - 1)
                {
                    $lines[] = $current_line;
                   
                    $line_widths[] = $line_width;
                }
               
                $last_width = $line_width;
                   
                $first_word = FALSE;
            }
           
            if($current_line)
            {
                $current_line = $item;
            }
        }
       
        $i = 0;
        foreach($lines as $line)
        {
            if($align == "center")
            {
                $left_offset = ($max_width - $line_widths[$i]) / 2;
            }
            elseif($align == "right")
            {
                $left_offset = ($max_width - $line_widths[$i] - 6);
            }
            if ($align == "left") {
                $left_offset = 5;
            }
            imagettftext($image, $size, $angle, $left + $left_offset, 
                $top + $largest_line_height + ($largest_line_height * $i), 
                $color, $font, $line);
            $i++;
        }
       
        return $largest_line_height * count($lines);
}

// Similar function for use with standard GD fonts.

function imageWriteString(&$img, $font, $text, $color, $position_x = 'center', $position_y = 'center') {
    // initialize internal variables
    $x = null;
    $y = null;

    if($font < 0 || $font > 5){ $font = 0; }
    $num = array(array(4.6, 6),
                 array(4.6, 6),
                 array(5.6, 12),
                 array(6.5, 12),
                 array(7.6, 16),
                 array(8.5, 16));

    $width = ceil(strlen($text) * $num[$font][0]);
    $height = $num[$font][1] + 2;

    // handle position x
    if (is_string($position_x)) {
        switch($position_x) {
            case 'left':
                $position_x = 5;
                break;
            case 'right':
                $position_x = -8;
                break;
            default:
            case 'center':
                $x     = (imagesx($img) - $width - 8) / 2;
                break;
        }
    }
    if (!isset($x)) {
        if(is_numeric($position_x)) {
            if ($position_x >= 0) {
                $x = $position_x; // left
            } else {
                $x = imagesx($img) - $width + $position_x - 8; // right
            }
        } else {
            $x     = (imagesx($img) - $width - 8) / 2; // default / error value: center
        }
    }

    // handle position y
    if (is_string($position_y)) {
        switch($position_y) {
            case 'top':
                $position_y = 5;
                break;
            case 'bottom':
                $position_y = -5;
                break;
            default:
            case 'center':
                $y     = (Imagesy($img) - ($num[$font][1] + 2))/2;
                break;
        }
    }
    if (!isset($y)) {
        if (is_numeric($position_y)) {
            if ($position_y >= 0) {
                $y = $position_y; // top
            } else {
                $y = Imagesy($img) - $height + $position_y; // bottom
            }
        } else {
            $y     = (Imagesy($img) - ($num[$font][1] + 2))/2; // default / error value: center
        }
    }
    imagestring($img, $font, $x, $y, $text, $color);
}

function ret_value($lookup) {
    global $SITE, $DATA;
    
    $rtn = array_search  ( $lookup  , $SITE['cvalues'] );
    
    if ($rtn !== FALSE) {
        return( $DATA[$rtn] );
    } else {
        return("-");
    }
}

############################################################################
# END OF MODULES
############################################################################

User avatar
beteljuice
Posts: 2950
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: Cumulus PHP-GD Banner

Post by beteljuice »

Simple answer is have you tried it :o

... and if you are updating everything, what about background graphic option (with comments) :shock:
Image
......................Imagine, what you will KNOW tomorrow !

Phil23
Posts: 496
Joined: Sat 16 Jul 2016 11:59 pm
Weather Station: Davis Vantage Pro2 Plus
Operating System: Win7 Pro
Location: Australia

Re: Cumulus PHP-GD Banner

Post by Phil23 »

beteljuice wrote:
Tue 14 Jan 2020 12:23 am
Simple answer is have you tried it :o

... and if you are updating everything, what about background graphic option (with comments) :shock:
Thanks for the reminder.

And no, not tested yet, but I did do the background graphics in my own Banner, so will look & bring that across.

Phil23
Posts: 496
Joined: Sat 16 Jul 2016 11:59 pm
Weather Station: Davis Vantage Pro2 Plus
Operating System: Win7 Pro
Location: Australia

Re: Cumulus PHP-GD Banner

Post by Phil23 »

beteljuice wrote:
Sun 12 Jan 2020 10:33 pm
and you can always view the source code of anybody's banner by .php?sce=view
Not quite getting that.

As in http://weather.inverellit.com/banner.php?sce=view ??

Should that somehow let me view the code in my php file?
Can't see it, looked in Dev view etc. But remember Web & php is not my strong suit.

Mapantz
Posts: 750
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 10 x64
Location: Dorset - UK
Contact:

Re: Cumulus PHP-GD Banner

Post by Mapantz »

Image

User avatar
beteljuice
Posts: 2950
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: Cumulus PHP-GD Banner

Post by beteljuice »

:oops: how many years using that ?
Image
......................Imagine, what you will KNOW tomorrow !

Phil23
Posts: 496
Joined: Sat 16 Jul 2016 11:59 pm
Weather Station: Davis Vantage Pro2 Plus
Operating System: Win7 Pro
Location: Australia

Re: Cumulus PHP-GD Banner

Post by Phil23 »

beteljuice wrote:
Tue 14 Jan 2020 11:40 am
:oops: how many years using that ?
It's gotta be a year or two.

It's not easy to follow & find the changes, hence my desire to put an updated one on the Wiki.

User avatar
beteljuice
Posts: 2950
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: Cumulus PHP-GD Banner

Post by beteljuice »

It's not easy to follow & find the changes,
Do you have something like DiffMerge ?

If you don't pay / register, you lose a few unimportant things and get a 'nag' screen - very useful tool !
Image
......................Imagine, what you will KNOW tomorrow !

Post Reply