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