laravel-medialibrary
laravel-medialibrary copied to clipboard
Implicit incompatible float to int conversion is deprecated
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
Wich version of the package? laravel version?
latest of both, but it began to happen a few weeks ago, just when I installed PHP8.1
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.
No, not related to that.
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.
@elfeffe Can you provide a test that demonstrates that this issue exists? The current unit tests indicate that it is working properly.
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