Deprecated warning: Float to int conversion in imagecopy() due to non-integer margins in AddWatermark operation

Created on 12 December 2024, 2 months ago

Problem/Motivation

The AddWatermark operation triggers a deprecated warning in PHP 8.1+ due to implicit float-to-int conversion. The lack of explicit type casting or rounding results in a loss of precision and a deprecated warning. This issue impacts compatibility with modern PHP versions.

PHP Version: 8.3.6

Steps to reproduce

  1. Install Drupal 10.3.*
  2. Install the Basic Watermark module, version 2.1.0
  3. Go to admin/config/media/image-styles/manage/media_library
  4. Add a new "Add watermark" effect
  5. After configuring the new effect, click "Add effect". You will be redirected to "admin/config/media/image-styles/manage/media_library" where you will see the error message: "Deprecated function: Implicit conversion from float 42.5 to int loses precision in Drupal\basic_watermark\Plugin\ImageToolkit\Operation\gd\AddWatermark->execute() (line 89 of modules/contrib/basic_watermark/src/Plugin/ImageToolkit/Operation/gd/AddWatermark.php)."

Proposed resolution

Explicitly cast or round the $margins['x'] and $margins['y'] values to integers before passing them to the imagecopy() function



After

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

2.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024