image
image copied to clipboard
Implicit conversion from float 359.99 to int loses precision
Hi,
I don't use this package directly, but I noticed a lot of warning messages in logs while developing a Laravel application and went down a rabbit hole I shouldn't..... The full warning message I get:
Implicit conversion from float 359.99 to int loses precision in
/var/www/html/vendor/intervention/image/src/Intervention/Image/Gd/Shapes/EllipseShape.php on line 58
This is caused by calling PHP's imagearc
function with end_angle
parameter of hardcoded float 359.99
.
According to the documentation, all parameters are integer type - hence the type casting on every single execution causes precision to be dropped to a round 359
.
I cannot figure out why full 360
was not used as a full circle angle, but given it was written 8 years ago, it might have been a workaround for another upstream issue or the spec might have changed over the years.
I see three ways to calm down the warning messages and set the hardcoded end_angle
to one of:
-
360
- this works ok -
(int) 359.99
- keep the original idea, but pre-cast to an integer -
359
- an integer it would end up with anyway
Unfortunately, I don't have a proper setup for testing this, so I shamelessly edited end_angle
in the vendor dir and checked my app to observe the changes.
My environment:
- WSL2, Ubuntu 22.04
- PHP 8.1.6
- Laravel 9.19.0
Same issue here. PHP 8.1.8
There is another issue at:
src/Intervention/Image/Gd/Font.php
+210
Just change from:
imagettftext($image->getCore(), $this->getPointSize(), $this->angle, $posx, $posy, $color->getInt(), $this->file, $this->text);
to
imagettftext($image->getCore(), $this->getPointSize(), $this->angle, intval($posx), intval($posy), $color->getInt(), $this->file, $this->text);
Thanks for this package. The needed change seems to be so simple. So please be kind and update.
Please use Version 3 of Intervention Image.