image icon indicating copy to clipboard operation
image copied to clipboard

Implicit conversion from float 359.99 to int loses precision

Open Pilskalns opened this issue 2 years ago • 2 comments

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.

image

My environment:

  • WSL2, Ubuntu 22.04
  • PHP 8.1.6
  • Laravel 9.19.0

Pilskalns avatar Jul 10 '22 10:07 Pilskalns

Same issue here. PHP 8.1.8

snapey avatar Jul 29 '22 17:07 snapey

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

leandro-lifepet avatar Sep 14 '22 22:09 leandro-lifepet

Thanks for this package. The needed change seems to be so simple. So please be kind and update.

lehnen avatar Feb 23 '23 12:02 lehnen

Please use Version 3 of Intervention Image.

olivervogel avatar Dec 08 '23 17:12 olivervogel