Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

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

Legacy Cumulus 1 release 1.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

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

Cumulus MX V4 Build Webtags Not working.

From Cumulus MX version 3 build 3044 the development baton passed to Mark Crossley. Mark has been responsible for all the Builds since, and has recently released Cumulus MX version 4. He has made the code available on GitHub. It is Mark's hope that others will join in this development, but at the very least he welcomes your ideas for future developments (see Cumulus MX Development suggestions).

Moderator: mcrossley

User avatar
PaulMy
Posts: 4355
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis VP2 Plus 24-Hour FARS
Operating System: Windows8 and Windows10
Location: Komoka, ON Canada
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by PaulMy »

Can we see the code in the banner?

Enjoy,
Paul
VP2+
C1 www.komokaweather.com/komokaweather-ca
MX https://komokaweather.com/cumulusmx/index.htm /index.html /index.php
MX https://komokaweather.com/cumulusmxwll/index.htm /index.html /index.php
MX https:// komokaweather.com/cumulusmx4/index.htm
Image
nicksnet
Posts: 38
Joined: Mon 23 Sep 2013 6:09 pm
Weather Station: Davis VP2 Plus inc 24-Hour FARS
Operating System: windows 11 x64
Location: Oshawa, Ontario, CANADA.
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by nicksnet »

Here's the Banner Code - Thanks for your help !!!

Code: Select all

<?php
############################################################################
# A Project of TNET Services, Inc.
############################################################################
#
#   Project:    Cumulus Project 
#   Package:    Cumulus Weather Banner
#   Module:     banner.php
#   Version:    3.0 - October 19th, 2008
#   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.
#
############################################################################
#   This document uses Tab 4 Settings
############################################################################
global $SITE;
$DATA   = array();
$SITE   = array();
$WX		= array();
############################################################################
# CONFIGURATION INFORMATION
############################################################################
$SITE['version']        = "3.0";
$SITE['hloc']           = "./";
$SITE['datafile']       = "realtime.txt";
$SITE['edatafile']		= "CUtags.php";
//$SITE['file']			= "ec-rss-top-warningSB.php";
$SITE['image_width']    = 550;
$SITE['image_height']   = 90;
#---------------------------------------------------------------------------
$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']       = "The Vicarage Weather Feed";
$SITE['location']		= "Oshawa, ON. Canada";
#---------------------------------------------------------------------------
// 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","ccloudbase","cbmeasure","cforecast","pondtemp");
$WX['edatafile'] = array(
	"ExtraTemp1","AirLinkPct_1hrIn","MoonPercent","sunrise","sunset");
############################################################################

############################################################################
# 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)
#   presstrend  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
#	heatindex	41		21.9		heat index
#   uvindex		43		3.2			uv index
#	cforecast	48		2			Cumulus forecast number as per strings.ini file
#	ccloudbase	52		1718		Cumulus cloudbase height in feet
#	cbaseunit	53		ft			Cumulus cloudbase units
############################################################################
// Path to our font file
$font1 = $SITE['fontdir'] . "arialbd.ttf";
$font2 = $SITE['fontdir'] . "arial.ttf";
$font3 = $SITE['fontdir'] . "verdana.ttf";  
$font4 = $SITE['fontdir'] . "ClarendonBT.ttf";
$font5 = $SITE['fontdir'] . "ShelleyAllegro.ttf";                                                                      
// Read data into array
$DATA = get_raw($SITE['hloc'] . $SITE['datafile'],' ');
$WX = get_raw($SITE['CUtags.php'] . $SITE['edatafile'],' ');
if(file_exists("CUtags.php")) { include("CUtags.php"); }
$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 = @imagecreatetruecolor($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);
$brightgreen        = imagecolorallocate($im, 0x4b, 0xDD, 0x4b);
$green				= imagecolorallocate($im, 0x00, 0xFF, 0x00);
$brightblue         = imagecolorallocate($im, 0x00, 0xFF, 0xFF);
$blue               = imagecolorallocate($im, 0x00, 0x00, 0x99);
$red                = imagecolorallocate($im, 0xff, 0x00, 0x00);
$indianred          = imagecolorallocate($im, 0x00, 0xFF, 0xFF);
$white              = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$yellow				= imagecolorallocate($im, 0xFF, 0xFF, 0x00);
$orange				= imagecolorallocate($im, 0xFF, 0x69, 0x00);
$violet				= imagecolorallocate($im, 0xFF, 0x00, 0xFF);

	$baseimg = imagecreatefrompng("Banner.png");
	
	imagecopy($im,$baseimg,0,0,0,0,$SITE['image_width'], $SITE['image_height']);
	imagedestroy($baseimg);
	
// Make a Border Around the box
ImageRectangle($im, 0, 0, $SITE['image_width'] -1 , 
    $SITE['image_height'] -1, $black);

// Print Cloudbase (top left)
$text = "Cloudbase: " . $DATA[52] .  ' ' . $DATA[53];
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 52, $white, $font1, $text, $SITE['image_width'], "left");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $white, "left", 1);
}

// Print Control Box Temp (top left)
$file_name = "https://api.thingspeak.com/channels/1517006/fields/1/last.txt?round=1";
$tempdata = file_get_contents($file_name);
$text = "Control Box Temp: " . ($tempdata) . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 44, $red, $font1, $text, $SITE['image_width'], "left");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $red, "left", 54);
}

// Print Moon Age (top left)
$text = "Moon: " . $WX['MoonPercent'] . "% " . "illuminated";
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 44, $white, $font1, $text, $SITE['image_width'], "left");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $white, "left", 11);
}

// Print Sun Rise (top left)
$text = "Sunrise: " . $WX['sunrise'];
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 44, $yellow, $font1, $text, $SITE['image_width'], "left");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $yellow, "left", 21);
}

// Print Station Name (top middle)
$text = $SITE['sitename'];
if ($SITE['usettf'] == "yes" ) {
    $size = 20;
    imagettftextbox($im, $size, 0, 0, 2, $yellow, $font4, $text, $SITE['image_width'], "center");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $yellow, "center", 1);
}

// Print Station Location (top middle)
$text = $SITE['location'];
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 2, $yellow, $font4, $text, $SITE['image_width'], "center");
} else {
    $size = 8;
    imageWriteString($im, $size, $text, $yellow, "center", 16);
}

// Print Air Quality and UV Index (center right)
$text = "AQI: " . $WX['AirLinkPct_1hrIn'] . " - UV: " . $DATA[43];
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 44, $violet, $font3, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $violet, "right", 42);
}

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

// Print ISS Battery Level (center right)
$file_name = "https://api.thingspeak.com/channels/1517006/fields/6/last.txt?round=1";
$tempdata = file_get_contents($file_name);
$text = "ISS Battery Level: " . ($tempdata) . 'V';
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 44, $red, $font1, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $red, "right", 54);
}

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

// Print Sun Set (top right)
$text = "Sunset: " . $WX['sunset'];
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 44, $red, $font1, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $red, "right", 21);
}

// Print Temp (Center)
$text = "Temp: " . ret_value("temp") . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 25;
    imagettftextbox($im, $size, 0, 0, 40, $red, $font1, $text, $SITE['image_width'], "center");
} else {
    $size = 5;
    imageWriteString($im, $size, $text, $red, "center", 41);
}

// Print Temp Trend (center)
$text = $DATA[25];
$weather_trend = $text * 2;
if ($weather_trend >= 6.0)
  $temp_trend_text = "Rising Rapidly " . ret_value("temptrendval") . '°' . ret_value("tempunit");
elseif ($weather_trend > 3.5)
  $temp_trend_text = "Rising Quickly " . ret_value("temptrendval") . '°' . ret_value("tempunit");
elseif ($weather_trend > 1.5)
  $temp_trend_text = "Rising " . ret_value("temptrendval") . '°' . ret_value("tempunit");
else if ($weather_trend > 0.1)
  $temp_trend_text = "Rising Slowly " . ret_value("temptrendval") . '°' . ret_value("tempunit");
elseif ($weather_trend > -0.1)
  $temp_trend_text = "Steady " . ret_value("temptrendval") . ' °' . ret_value("tempunit");
elseif ($weather_trend > -1.5)
  $temp_trend_text = "Falling Slowly " . ret_value("temptrendval") . '°' . ret_value("tempunit");
elseif ($weather_trend > -3.5)
  $temp_trend_text = "Falling " . ret_value("temptrendval") . '°' . ret_value("tempunit");
elseif ($weather_trend > -6.0)
  $temp_trend_text = "Falling Quickly" . ret_value("temptrendval") . '°' . ret_value("tempunit");
else
  $temp_trend_text = "Falling Rapidly " . ret_value("temptrendval") . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 41, $red, $font1, $text, $SITE['image_width'], "center");
} else {
    $size = 2;
    imageWriteString($im, $size, $temp_trend_text, $red, "center", 54);
}

// Print Humitidy and Dewpt (center left)
$text = "Hum: " . ret_value("hum") . "% - " . "DewPt: " . ret_value("dew") . '°' . ret_value("tempunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 41, $orange, $font1, $text, $SITE['image_width'], "left");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $orange, "left", 42);
}

// Print Forecast (center)
$text = $WX['forecast'];
if ($SITE['usettf'] == "yes" ) {
    $size = 2;
    imagettftextbox($im, $size, 0, 0, 30, $brightgreen, $font1, $text, $SITE['image_width'], "center");
} else {
    $size = 1;
    imageWriteString($im, $size, $text, $brightgreen, "center", 34);
}

// Print windspeed (bottom left)
$text = "Wind: " . ret_value("wdir") . " @ " . ret_value("wspeed") . ' ' . ret_value("windunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 60, $black, $font1, $text, $SITE['image_width'], "left");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $black, "left", 65);
}

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

// Print Rain (bottom right)
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 = 8;
    imagettftextbox($im, $size, 0, 0, $py, $blue, $font1, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $blue, "right", 65);
}

// Print Monthly Rainfall (bottom right)
$text = "Monthly Rainfall: " . ret_value("rmonth") . ' ' . ret_value("rainunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 65, $blue, $font1, $text, $SITE['image_width'], "right");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $blue, "right", 76);
}

// Print Baro (bottom center)
$text = "Baro: " . ret_value("press") . ' ' . ret_value("pressunit");
if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 65, $green, $font1, $text, $SITE['image_width'], "center");
} else {
    $size = 2;
    imageWriteString($im, $size, $text, $green, "center", 65);
}

// Print Baro Trend (bottom center)
$text = $DATA[18];
$weather_trend = $text * 2;
if ($weather_trend >= 6.0)
  $pressure_trend_text = "Rising Rapidly " . ret_value("presstrend") . ' ' . ret_value("pressunit");
elseif ($weather_trend > 3.5)
  $pressure_trend_text = "Rising Quickly " . ret_value("presstrend") . ' ' . ret_value("pressunit");
elseif ($weather_trend > 1.5)
  $pressure_trend_text = "Rising " . ret_value("presstrend") . ' ' . ret_value("pressunit");
else if ($weather_trend > 0.1)
  $pressure_trend_text = "Rising Slowly " . ret_value("presstrend") . ' ' . ret_value("pressunit");
elseif ($weather_trend > -0.1)
  $pressure_trend_text = "Steady " . ret_value("presstrend") . ' ' . ret_value("pressunit");
elseif ($weather_trend > -1.5)
  $pressure_trend_text = "Falling Slowly " . ret_value("presstrend") . ' ' . ret_value("pressunit");
elseif ($weather_trend > -3.5)
  $pressure_trend_text = "Falling " . ret_value("presstrend") . ' ' . ret_value("pressunit");
elseif ($weather_trend > -6.0)
  $pressure_trend_text = "Falling Quickly " . ret_value("presstrend") . ' ' . ret_value("pressunit");
else
  $pressure_trend_text = "Falling Rapidly " . ret_value("presstrend") . ' ' . ret_value("pressunit");

if ($SITE['usettf'] == "yes" ) {
    $size = 8;
    imagettftextbox($im, $size, 0, 0, 75, $green, $font1, $text, $SITE['image_width'], "center");    
} else {
    $size = 2;
    imageWriteString($im, $size, $pressure_trend_text, $green, "center", 76);
}

// 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
HansR
Posts: 6926
Joined: Sat 20 Oct 2012 6:53 am
Weather Station: GW1100 (WS80/WH40)
Operating System: Raspberry OS/Bookworm
Location: Wagenborgen (NL)
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by HansR »

@nicksnet: could you please edit the post and put that code between the code markup - the '</>' button.
Also one meteo image header in the signature should be enough.
Thank you.
Hans

https://meteo-wagenborgen.nl
CMX build 4070+ ● RPi 4B ● Linux 6.6.62+rpt-rpi-v8 aarch64 (bookworm) ● dotnet 8.0.1
BlueSky: https://bsky.app/profile/wagenborgenwx.bsky.social
freddie
Posts: 2870
Joined: Wed 08 Jun 2011 11:19 am
Weather Station: Davis Vantage Pro 2 + Ecowitt
Operating System: GNU/Linux Ubuntu 24.04 LXC
Location: Alcaston, Shropshire, UK
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by freddie »

HansR wrote: Mon 30 Sep 2024 9:33 pm @nicksnet: could you please edit the post and put that code between the code markup - the '</>' button.
I've done the edit because it was irritating me too :)
Freddie
Image
User avatar
PaulMy
Posts: 4355
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis VP2 Plus 24-Hour FARS
Operating System: Windows8 and Windows10
Location: Komoka, ON Canada
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by PaulMy »

Thanks,
I am not a coder and don't use that banner so not much help, but I think this is where your scripts calls for the data:

Code: Select all

// Print Air Quality and UV Index (center right)
$text = "AQI: " . $WX['AirLinkPct_1hrIn'] . " - UV: " . $DATA[43];
if ($SITE['usettf'] == "yes" ) {
$size = 8;
imagettftextbox($im, $size, 0, 0, 44, $violet, $font3, $text, $SITE['image_width'], "right");
} else {
$size = 2;
imageWriteString($im, $size, $text, $violet, "right", 42);
}
and the source file has:

Code: Select all

$AirLinkPct_1hrIn           = "100"; //   AirLink Data
$AirLinkPct_1hrOut          = "--"; //   AirLink Data
$AirLinkPct_24hrIn          = "100"; //   AirLink Data
$AirLinkPct_24hrOut         = "--"; //   AirLink Data
$AirLinkPct_3hrIn           = "100"; //   AirLink Data
$AirLinkPct_3hrOut          = "--"; //   AirLink Data
$AirLinkPct_NowcastIn       = "100"; //   AirLink Data
$AirLinkPct_NowcastOut      = "--"; //   AirLink Data
so presume $AirLinkPct_1hrIn ="100"; is source for $WX['AirLinkPct_1hrIn'] but don't know why it does not print. The only thing I can think of is some syntax error. Is there anything in your hosting site error_log?

The " - UV: " . $DATA[43]; does print but comes from a different source.

Enjoy,
Paul

Thanks Hans and freddie, but I stumbled along before you [code} coded it [/code]
VP2+
C1 www.komokaweather.com/komokaweather-ca
MX https://komokaweather.com/cumulusmx/index.htm /index.html /index.php
MX https://komokaweather.com/cumulusmxwll/index.htm /index.html /index.php
MX https:// komokaweather.com/cumulusmx4/index.htm
Image
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by mcrossley »

You should be using the tag - "AirLinkAqiPm2p5_3hrIn" - that is the only one valid for the Canada AQHI, which you can see has a value of 100 in the file.

Though personally I do not think it should be on your banner as it is not the AQI for the location, merely inside your house or wherever!
If you do use it, I think it should be clear it is an indoor value.

EDIT: Though the value of 100 for the AirLinkAqiPm2p5_3hrIn does not look right either. If the PM 2.5 3-hour average is 4.9, then I would expect the AQI to be 1!

Is the web tag correct in the source tag file?
nicksnet
Posts: 38
Joined: Mon 23 Sep 2013 6:09 pm
Weather Station: Davis VP2 Plus inc 24-Hour FARS
Operating System: windows 11 x64
Location: Oshawa, Ontario, CANADA.
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by nicksnet »

Hi Mark,

Thank you for your time in this, I understand where your coming from, and yes, indoor AQI looking like outdoor is a no no, guess that one went over my head :groan: Anyway, long and short of it, because I can't get non of the Airlink tags to work in the Banner script, i'm giving it the big" heave ho"

This all started out with wanting my control box temperature reading and ISS voltage displayed on the banner, and things progressed from there.....you know how it goes, you get one thing working and want to explore further, guess that's how we all learn.

Anyway thanks again for your time, and also thanks to Paul.

Keep up the great work !

Nick.
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by mcrossley »

The banner script should work with...

Code: Select all

$WX['AirLinkPct_1hrIn']
changed to

Code: Select all

$WX['AirLinkPct_3hrIn']
But the value for 'AirLinkPct_3hrIn' looks very suspicious- The source file for the tags needs looking, I suspect it has the wrong web tag in there for the 'AirLinkPct_3hrIn' value. It looks like it might be using the percentage received tag rather than the PM 2.5 3-hour tag.
nicksnet
Posts: 38
Joined: Mon 23 Sep 2013 6:09 pm
Weather Station: Davis VP2 Plus inc 24-Hour FARS
Operating System: windows 11 x64
Location: Oshawa, Ontario, CANADA.
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by nicksnet »

hmm tried that.

I'll hang out for other ideas, and work on it from my end. There's an answer to this somewhere, it can't hide forever :lol:

Thanks again.

Nick.
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by mcrossley »

Sorry, I'm such an idiot! I've been reading what I expected to see, not what was there in front of me. :bash:

We have both been using the wrong web tags.

Try this: http://<cmx_ip_address>:8998/api/tags/process.json?AirLinkPm2p5_3hrIn&AirLinkAqiPm2p5_3hrIn

The tag you should be using for the AQI is: AirLinkAqiPm2p5_3hrIn
broadstairs
Posts: 1184
Joined: Thu 14 Aug 2008 7:17 am
Weather Station: Ecowitt GW2000/GW3000
Operating System: Linux openSUSE LEAP
Location: Broadstairs, Kent, UK
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by broadstairs »

That script shown earlier uses

Code: Select all

$SITE['edatafile']		= "CUtags.php";
and

Code: Select all

$WX['edatafile'] = array(
	"ExtraTemp1","AirLinkPct_1hrIn","MoonPercent","sunrise","sunset");
but looking at the CUtags file on your website there are no AirLink variables in it.

Stuart
Currently running CMX V4.4.2 4085 on Linux openSUSE Leap
nicksnet
Posts: 38
Joined: Mon 23 Sep 2013 6:09 pm
Weather Station: Davis VP2 Plus inc 24-Hour FARS
Operating System: windows 11 x64
Location: Oshawa, Ontario, CANADA.
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by nicksnet »

Hi Stuart,

I saw that myself, and to get around that I loaded Cumuluswebtags.php instead of CUtags.php for testing and got same results, cumuluswebtags contains all possible tags with Airlink populated, and still the script didn't want to work with those Airlink tags, but worked with all other tags required by script.

Nick.
broadstairs
Posts: 1184
Joined: Thu 14 Aug 2008 7:17 am
Weather Station: Ecowitt GW2000/GW3000
Operating System: Linux openSUSE LEAP
Location: Broadstairs, Kent, UK
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by broadstairs »

nicksnet wrote: Tue 01 Oct 2024 2:12 pm Hi Stuart,

I saw that myself, and to get around that I loaded Cumuluswebtags.php instead of CUtags.php for testing and got same results, cumuluswebtags contains all possible tags with Airlink populated, and still the script didn't want to work with those Airlink tags, but worked with all other tags required by script.

Nick.
OK then I'm out of ideas as well...

Stuart
Currently running CMX V4.4.2 4085 on Linux openSUSE Leap
nicksnet
Posts: 38
Joined: Mon 23 Sep 2013 6:09 pm
Weather Station: Davis VP2 Plus inc 24-Hour FARS
Operating System: windows 11 x64
Location: Oshawa, Ontario, CANADA.
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by nicksnet »

Hi Stuart,

Thanks for your help, any ideas are appreciated, it's not a big deal anyway, and as Mark said, indoor AQI doesn't belong on the Banner, but I guess I hate being beaten by software when it should work.

All the best.

Nick.
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Cumulus MX V4 Build Webtags Not working.

Post by mcrossley »

I saw that myself, and to get around that I loaded Cumuluswebtags.php instead of CUtags.php for testing and got same results, cumuluswebtags contains all possible tags with Airlink populated, and still the script didn't want to work with those Airlink tags, but worked with all other tags required by script.
And did you change...

Code: Select all

$WX['edatafile'] = array(
	"ExtraTemp1","AirLinkPct_1hrIn","MoonPercent","sunrise","sunset");
To stop it using the 1-hour percentage messages received to using the 3-hour AQI value?
Post Reply