JamesHeinrich / phpThumb

phpThumb() - The PHP thumbnail generator
Other
315 stars 141 forks source link

PHP since 8.1.26: Deprecated: Implicit conversion from float xxx.yyyyyyy to int loses precision in phpThumb\phpthumb.filters.php on line 1022 #220

Closed andymnc closed 3 months ago

andymnc commented 3 months ago

On php 8.1.26 (or higher versions), phpthumb.filters.php > SourceTransparentColorMask > $grayLevel could generate strange floats (in my case from 245 it becomes 245.00000000000003) and the next $newColor = imagecolorallocate($gdimg_mask, $grayLevel, $grayLevel, $grayLevel); on line 1022, makes php return the error: Deprecated: Implicit conversion from float xxx.yyyyyyy to int loses precision in phpThumb\phpthumb.filters.php on line 1022 where xxx.yyyyyyy is an actual float.

Temporary solved with: $newColor = imagecolorallocate($gdimg_mask, (int)$grayLevel, (int)$grayLevel, (int)$grayLevel); at 1022 or $grayLevel = (int) (min($cutoffRange, max(0, -$min_limit + $colorDiff)) * (255 / max(1, $cutoffRange))); at 1021

JamesHeinrich commented 3 months ago

Are you sure you're using the current version of phpThumb (1.7.22-202312071641)? Your line numbers are off-by-2, and there's already (int) where $grayLevel is set: https://github.com/JamesHeinrich/phpThumb/blob/master/phpthumb.filters.php#L1023-L1024

andymnc commented 3 months ago

Are you sure you're using the current version of phpThumb (1.7.22-202312071641)? Your line numbers are off-by-2, and there's already (int) where $grayLevel is set: https://github.com/JamesHeinrich/phpThumb/blob/master/phpthumb.filters.php#L1023-L1024

You are right. Now on last version and it works. Thank you