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.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | auto_retina-implicit-conversion-from-float-3350843-5.patch | 1.01 KB | vaish |
| #2 | auto_retina-implicit-conversion-from-float-3350843-2.patch | 1.01 KB | vaish |
Comments
Comment #2
vaish commentedPatch attached.
Comment #3
vaish commentedComment #4
chrisolofThe 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
Comment #5
vaish commentedPatch updated as per #4
Comment #6
chrisolofConfirming that the patch in #5 fixes the bug in my tests on a PHP 8.1 environment.
Comment #7
chrisolofThis has been merged into our 2.x branch and is included in the latest 2.0.0 release.