Problem/Motivation
On upgrading PHP to version 8 from 7.4 we noticed the following issue notifications:
Deprecated function: Implicit conversion from float 10.5 to int loses precision in image_gd_adjustlevels() (line 1195 of .../contrib/imagecache_actions/coloractions/imagecache_coloractions.module).
Deprecated function: Implicit conversion from float 27.359375 to int loses precision in image_gd_coloroverlay() (line 413 of .../imagecache_actions/coloractions/imagecache_coloractions.module).I've attached the patch file that addressed the issue for us.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3328643-3.patch | 1.26 KB | poker10 |
| imagecache_coloractions-php8.patch | 2.53 KB | Anonymous (not verified) |
Comments
Comment #1
Anonymous (not verified) commentedianlavinrady created an issue. See original summary.
Comment #2
fietserwinThe PHP manual does indeed state: When converting from float to int, the number will be rounded towards zero. As of PHP 8.1.0, a deprecation notice is emitted when implicitly converting a non-integral float to int which loses precision.
So, an explicit conversion is needed. However, should we round to the nearest integer value or use the "default" round towards zero. Current/old behaviour was to round towards zero, and that is what the patch does. But I think that, theoretically, we want to round to the nearest whole number as that gives a slightly better result, though I have no idea if the human eye can detect such a difference at all. In this sense this issue becomes a bug, revealed by stricter warnings in the latest PHP version.
Comment #3
poker10 commentedHere is the alternate approach with rounding to the nearest integer. I have also removed the rounding of the last parameter (
$source['alpha']), as this should be an integer (see the docs forimagecolorsforindex()).Comment #5
poker10 commentedCommitted the variant with rounding, thanks all!