Problem/Motivation

Setting quality multiplier to a value other than 1 may result in value for quality becoming float (decimal number) instead of integer. Gd library expects quality to be integer and triggers the following warning:

Deprecated function: Implicit conversion from float 76.5 to int loses precision in Drupal\system\Plugin\ImageToolkit\GDToolkit->save() (line 258 of web/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php)
#0 web/core/includes/bootstrap.inc(347): _drupal_error_handler_real()
#1 [internal function]: _drupal_error_handler()
#2 web/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php(258): imagejpeg()
#3 web/core/lib/Drupal/Core/Image/Image.php(125): Drupal\system\Plugin\ImageToolkit\GDToolkit->save()
#4 web/core/modules/image/src/Entity/ImageStyle.php(332): Drupal\Core\Image\Image->save()
#5 web/modules/contrib/auto_retina/src/Entity/RetinaImageStyle.php(50): Drupal\image\Entity\ImageStyle->createDerivative()
#6 web/modules/contrib/auto_retina/src/Entity/RetinaImageStyleWithPipeline.php(27): Drupal\auto_retina\Entity\RetinaImageStyle->createDerivative()

Steps to reproduce

1. Set image toolkit to Gd and JPEG Quality to 85%.
2. Set auto retina quality multiplier to 0.9.
3. Upload new image or update existing one.
4. Visit the page with the new/updated image on the computer with the retina display (or emulate retina display with web developer tools).

This will trigger auto retina module to generate new derivative. Image Quality will be set to 76,5 (85*0.9) and Gd will complain about receiving the float instead of integer.

Proposed resolution

Convert quality to integer.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

vaish created an issue. See original summary.

vaish’s picture

Status: Active » Needs review
StatusFileSize
new1.01 KB

Patch attached.

vaish’s picture

Title: Implicit conversion from float to int loses precision » Gd library: Implicit conversion from float to int loses precision
Issue summary: View changes
chrisolof’s picture

The patch in #2 is working in my tests on a PHP 8.1 environment. The only change I would suggest is moving from intval() to typecasting (int) since:

- We don't need to adjust the base for the conversion
- Typecasting to int is quite a bit faster

vaish’s picture

Patch updated as per #4

chrisolof’s picture

Confirming that the patch in #5 fixes the bug in my tests on a PHP 8.1 environment.

chrisolof’s picture

Version: 8.x-1.3 » 2.x-dev
Status: Needs review » Fixed

This has been merged into our 2.x branch and is included in the latest 2.0.0 release.

Status: Fixed » Closed (fixed)

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