From 393c997eb0263f0394bdf7ea8be9e7b28f9dd57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4cke?= Date: Thu, 7 Dec 2023 14:20:11 +0100 Subject: [PATCH] Fix warnings for upcoming PHP 8.1 I got the following Notice while using the last image-generator version: ``` NOTICE: PHP message: PHP Deprecated: Implicit conversion from float 219.5 to int loses precision in /var/www/html/vendor/nicoverbruggen/image-generator/src/ImageGenerator.php on line 111 ``` I have seen that similar fixes have already been applied to other parts of the codebase, but these two lines were missing. To address this, I have explicitly cast the floating-point values to integers where `$x` and `$y` coordinates are calculated. This change aligns with the fixes made elsewhere in the code by you and ensures compatibility with PHP 8's type enforcement, preventing the deprecation notice related to precision loss during the float-to-int conversion. This should maintain the functionality while adhering to PHP 8's stricter type requirements. I hope you can add this fix into the main codebase. This modification has resolved the issue in my environment, and I believe it would be beneficial for other users as well. Looking forward to seeing this enhancement in the next update of the image-generator. :) --- src/ImageGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ImageGenerator.php b/src/ImageGenerator.php index 66f56d0..d4ce1a6 100644 --- a/src/ImageGenerator.php +++ b/src/ImageGenerator.php @@ -111,8 +111,8 @@ public function generate($text = "", $path = null, $size = null, $bgHex = null, $imageResource, $size, 0, - $x, - $y, + (int) $x, + (int) $y, $allocatedFgColor, $font, $text