Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.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
- Install Drupal 10.3.*
- Install the Basic Watermark module, version 2.1.0
- Go to admin/config/media/image-styles/manage/media_library
- Add a new "Add watermark" effect
- 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
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | Screenshot 2025-09-05 at 5.56.12 PM.png | 430.57 KB | sandeep_k |
| success.png | 268.9 KB | eric.vvf | |
| 2.png | 41.79 KB | eric.vvf | |
| 01.png | 329.6 KB | eric.vvf |
Issue fork basic_watermark-3493643
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
eric.vvf commentedComment #4
ekapus commentedMikechr, can we get this reviewed and merged?? I'd love to solve this for my projects with an update instead of manually applying the fix.
Comment #5
ekapus commentedI also found another place this happens, on line 157.
Updating it to this solves it:
$watermark_image = imagescale($watermark_image, (int) $watermark['width'], (int) $watermark['height']);Comment #6
sandeep_k commentedI attempted to reproduce this issue on Drupal version 10.3.1-dev by following all the steps mentioned above. However, I was unable to replicate the error on my D10 setup. I’m not sure if any additional steps are required. I’ve included the results here after adding and saving the image style.
Comment #7
mikechr commentedI'm happy to merge this, I'll wait for @ekapus to add the extra fix he mention at #5
Comment #8
vinodhini.e commentedHi, I encountered this issue on Drupal 10.5.1.
Steps I followed:
Installed the module on Drupal 10.5.1.
Created a new image style and added the Add Watermark effect.
Encountered the warning message when trying to save the effect.
Applied Merge Request #4.
Repeated the same steps to add the watermark effect.
The warning message still appears, and the issue is not resolved by this patch.
Comment #9
eric.vvf commentedExtra validation added, @mikechr
Comment #10
mikechr commentedMerged