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.

CommentFileSizeAuthor
#3 3328643-3.patch1.26 KBpoker10
imagecache_coloractions-php8.patch2.53 KBAnonymous (not verified)

Comments

Anonymous’s picture

ianlavinrady created an issue. See original summary.

fietserwin’s picture

The 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.

poker10’s picture

Assigned: » Unassigned
StatusFileSize
new1.26 KB

Here 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 for imagecolorsforindex()).

  • poker10 committed b4f25d33 on 7.x-1.x
    Issue #3328643 by ianlavinrady, poker10: Deprecated function: Implicit...
poker10’s picture

Version: 7.x-1.13 » 7.x-1.x-dev
Status: Needs review » Fixed

Committed the variant with rounding, thanks all!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.