Page 14 of 14

Re: CloudBase script for Cumulus Ver CU1.5

Posted: Fri 24 Jan 2025 1:46 am
by JennyLeez
The error I am getting is line 382 in both
PHP version 8.0.30

http://wairoa.net/weather/cloudbaseCUmx.php

and
8.1.31

Code: Select all

$baro			= round(str_replace(',', '.', $press));	//	convert comma decimal to '.'
I downloaded the file above you attached and uploaded without changing anything.
Thank you for your help so far :)
Cheers
Jenny

Re: CloudBase script for Cumulus Ver CU1.5

Posted: Fri 24 Jan 2025 2:42 am
by BCJKiwi
Sorry I am at a loss as to why it works for me and not for you two.

Re: CloudBase script for Cumulus Ver CU1.5

Posted: Fri 24 Jan 2025 8:45 am
by water01
I noticed that you do not run all the options, or at least they were not set in the source you posted.

I run all the options

Image

Could that be the problem?

Re: CloudBase script for Cumulus Ver CU1.5

Posted: Fri 24 Jan 2025 11:11 am
by JennyLeez
Hi water01
Correct I only want the cloud stuff. Like it simple.

I have finally succeeded and it now displays. I am missing the moon but they may be because I have hid a few lines :?
(Beteljuice will be rolling in his grave)

http://wairoa.net/weather/cloudbaseCUmx.php

I have hid 5 lines that threw out error messages as I had no idea how to fix them. Waters01 also had issues with 601 or 602
382
601
602
742
743

That is 1 of 3 issues I have.
I suggest you go on holiday Brian before I put the second SOS up :)

Cheers and thanks :)
Jenny

Re: CloudBase script for Cumulus Ver CU1.5 and PHP 8.1.x

Posted: Mon 27 Jan 2025 10:41 am
by lse-cumulus
Hi Jenny,
I will look into all the mentioned lines/issues in more detail and also try to test it out in a PHP 8.1.31 development/debug environment.

But a first fast answer: The problems fall into two (2) groups:
(1) lines 382, 742 and 743: are about typecasting between string/float datatype with function (round)
Uncaught TypeError: round(): Argument #1 ($num) must be of type int|float, string given
That sounds like PHP version dependent.
That should be solveable (theoretically, but I will also make some tests) by typecasts or by skipping the round () function at all. Only unlikely problem could be when in the datastring no numeric data is stored at all during runtime (e.g. $press = "leo").

Code: Select all

// line-382:
// old code: $baro = round(str_replace(',', '.', $press));	
// new code-1:
$baro = (string) round( (float) (str_replace(',', '.', $press)));	
// or new code-2 without rounding:  	$baro = str_replace(',', '.', $press);	

// lines-742-743:
// old code: 	$txtH = round($humidity) . '%'; $sizH = strlen($txtH) * imagefontwidth(3);
// new code-1:
$txtH = ((string) (round((float) $humidity))) . '%';
$sizH = strlen($txtH) * imagefontwidth(3); //after line before is fixed and $txtH is (string) then no change should be required here as strlen() and imagefontwidth() return both (int)
// or new code-2 without rounding: $txtH = $humidity . '%'; $sizH = strlen($txtH) * imagefontwidth(3);

(2) lines 601, 602: here I need more time to investigate in more detail the issues with GD graphics library;
Uncaught TypeError: imagecopyresampled(): Argument #2 ($src_image) must be of type GdImage, bool given
The error is raised in function imagecopyresampled(), but can be a transient error that is propagated from previous function calls to imagerotate() and imagecreatefrompng() as the status variables $image and $rotate are not checked for false. So earlier function calls could have failed, e.g. the $src_file that should contain the moonimage for all phase percentages might not be present on the server location ...
That does not look like PHP version related problem but environment related issue.
Could need some debugging or adding some safety checks to the code ...

Code: Select all

/* old code
	$image = imagecreatefrompng($src_file);
	if ($ns == 'N') {$rotate = $image;} else { $rotate = imagerotate($image, 180, 0);}  
	imagecopyresampled($temp_image, $rotate, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
*/
// suggested new code to locate the error:
	$image = imagecreatefrompng($src_file);
	if (!$image) {echo "file $src_file not found";}
	if ($ns == 'N') {$rotate = $image;} else { $rotate = imagerotate($image, 180, 0);}  // sutne
	 if (!$rotate) {echo "cannot rotate image";}
	imagecopyresampled($temp_image, $rotate, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);

Re: CloudBase script for Cumulus Ver CU1.5

Posted: Mon 27 Jan 2025 12:56 pm
by water01
I have found the problem with the imagecreate.

Quite simply it is caused by the gradual upgrading. at some point it was modified to use the CumulusMX Moon Percentage and what was forgotten was where those percentages were held (source) and updating the image libraries to include them in the correct place. Consequently the images cannot be found and the image creation fails.

I have now fixed all of this in this version

Copy this version into your website and add/replace the cb folder in your images directory with this one and all should work according to my testing on PHP 8.1.31.
DJcloudbase.zip
See here https://www.dmjsystems.co.uk/weatherbos/index.php half way down the page.

Re: CloudBase script for Cumulus Ver CU1.5

Posted: Mon 27 Jan 2025 8:33 pm
by lse-cumulus
Jenny,
David found the problem with the imagecreate and provided a fix.

I could verify that the code changes for $baro and $txtH are working under PHP 8.1.31. But these workarrounds are only needed when the strings $press and $humidity are containing no numeric values, like for example an empty string "". In previous PHP versions the round () function was tolerant and calculated 0, with PHP 8.1 the round () function now would return a TypeError.
I think in your environment $press and and $humidity have been empty (as you are not using these options) and therefore you got the problem when upgrading to PHP 8.1.
You can use code-1 or code-2 workarround or you could simply add hardcoded values like $humidity=0;
The cloudbase php scripts has builtin test functions that show that $humidity is indeed emtpy in your environment.
https://wairoa.net/weather/cloudbaseCUmx.php?html=1

Re: CloudBase script for Cumulus Ver CU1.5

Posted: Mon 27 Jan 2025 10:05 pm
by JennyLeez
Good morning,

I note watero1 did not change the code so I was at 2 odds as to which way to go.
So I decided to change the code to Leo's which is now running without errors.
I deleted and uploaded water01 CB folder and will now wait until tonight to see if the moon appears, the whole 3% of it .. lol

Many many thanks to you both for your help :)

Cheers
Jenny

Re: CloudBase script for Cumulus Ver CU1.5

Posted: Tue 28 Jan 2025 10:23 am
by JennyLeez
Good Evening,

So 2% moon is not showing so I will have to wait for a few days :)

The cloudbase image initially did not load. I did not have Nmoonpct.png
so I changed Nmoon0pct.png and that fixed it.
But that of course is the northern Herm. and I am going to need the southern herm.
I will touch base with Leo tomorrow. Right now bed is calling.

I also had to use the lines above for 601 and 602 that Leo changed.

This upgraded script ( when finished ) needs to be placed on the first page for anyone else needing it for 8.1.31. otherwise like many of the scripts I have been searching for, these changes will become lost in between the never increasing pages.
I will see what Brian thinks.

Cheers
Jenny