laravel-medialibrary icon indicating copy to clipboard operation
laravel-medialibrary copied to clipboard

Implicit incompatible float to int conversion is deprecated

Open elfeffe opened this issue 2 years ago • 5 comments

I'm getting this error:

Implicit conversion from float 40492.52199999999 to int loses precision in /media/psf/www/filament-commerce/vendor/spatie/laravel-medialibrary/src/ResponsiveImages/WidthCalculator/FileSizeOptimizedWidthCalculator.php on line 46

It's related to https://github.com/spatie/laravel-medialibrary/issues/2678 And seems to be a problem related to PHP 8.1 https://php.watch/versions/8.1/deprecate-implicit-conversion-incompatible-float-string

elfeffe avatar Jun 21 '22 11:06 elfeffe

Wich version of the package? laravel version?

fredsal avatar Jun 21 '22 14:06 fredsal

latest of both, but it began to happen a few weeks ago, just when I installed PHP8.1

elfeffe avatar Jun 22 '22 11:06 elfeffe

I think it can be related to my images, I allow the user to modify the size using a drag&drop cropper, it may generate float size for images. I will check it. Anyway, I think this package should handle that possibility.

elfeffe avatar Jun 22 '22 11:06 elfeffe

No, not related to that.

elfeffe avatar Jun 22 '22 12:06 elfeffe

The deprecation message is triggered when calculating responsive image width by /ResponsiveImages/WidthCalculator/FileSizeOptimizedWidthCalculator.php and method finishedCalculating(int $predictedFileSize, int $newWidth). Method calculateWidths() from the same class passes $predictedFileSize parameter which is not integer as required. It needs to be rounded and casted to int first.

vladski avatar Aug 23 '22 03:08 vladski

@elfeffe Can you provide a test that demonstrates that this issue exists? The current unit tests indicate that it is working properly.

patinthehat avatar Nov 21 '22 14:11 patinthehat

Hi, I solved this in a pr (merged) not long ago https://github.com/spatie/laravel-medialibrary/pull/3145

@elfeffe can you double check the package version

QuentinGab avatar Jan 31 '23 16:01 QuentinGab