Skip to content

Stop GD insert filling watermark bbox with black (optimized)#1489

Merged
olivervogel merged 5 commits into
developfrom
bugfix/insert-gd-transparent-base
May 21, 2026
Merged

Stop GD insert filling watermark bbox with black (optimized)#1489
olivervogel merged 5 commits into
developfrom
bugfix/insert-gd-transparent-base

Conversation

@olivervogel
Copy link
Copy Markdown
Member

insertTransparent() copied the base region into an opaque-black scratch canvas, layered the watermark on top, and merged it back with imagecopymerge(). Two problems: the black fill stuck wherever the base was transparent, so the watermark's bbox came out black on alpha PNGs; and imagecopymerge ignores source alpha, so partial watermark alpha was lost on the way back.

Build a faded copy of the watermark by scaling each pixel's alpha by the transparency factor, then composite with imagecopy(). GD does the blending instead of imagecopymerge, so transparent base pixels stay put and partial watermark alpha survives.

Regression test inserts circle.png on a 50x50 transparent canvas at transparency=0.5 and asserts the watermark's transparent corner is still transparent after insert.

Also drop the unused CanConvertRange trait and the trailing imagedestroy() call (no-op since PHP 8.0).

nlemoine and others added 3 commits May 20, 2026 15:17
insertTransparent() copied the base region into an opaque-black scratch canvas, layered the watermark on top, and merged it back with imagecopymerge(). Two problems: the black fill stuck wherever the base was transparent, so the watermark's bbox came out black on alpha PNGs; and imagecopymerge ignores source alpha, so partial watermark alpha was lost on the way back.

Build a faded copy of the watermark by scaling each pixel's alpha by the transparency factor, then composite with imagecopy(). GD does the blending instead of imagecopymerge, so transparent base pixels stay put and partial watermark alpha survives.

Regression test inserts circle.png on a 50x50 transparent canvas at transparency=0.5 and asserts the watermark's transparent corner is still transparent after insert.

Also drop the unused CanConvertRange trait and the trailing imagedestroy() call (no-op since PHP 8.0).
@olivervogel olivervogel changed the title Stop GD insert filling watermark bbox with black Stop GD insert filling watermark bbox with black (optimized) May 20, 2026
@olivervogel olivervogel merged commit ffe5ad1 into develop May 21, 2026
12 checks passed
@olivervogel olivervogel deleted the bugfix/insert-gd-transparent-base branch May 21, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants