Skip to content

Preserve transparency when pasting with alpha on the Imagick driver#878

Merged
mlocati merged 2 commits into
php-imagine:developfrom
nlemoine:fix/imagick-paste-alpha-transparency
Jun 3, 2026
Merged

Preserve transparency when pasting with alpha on the Imagick driver#878
mlocati merged 2 commits into
php-imagine:developfrom
nlemoine:fix/imagick-paste-alpha-transparency

Conversation

@nlemoine

@nlemoine nlemoine commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

paste() with an alpha < 100 on the Imagick driver paints a "black box" over the transparent areas of the pasted image. Paste a watermark that has a transparent surround at, say, 50% opacity and the whole bounding box comes back as a semi-opaque dark rectangle instead of just the visible part fading.

Culprit is setImageAlpha($alpha / 100) (and the setImageOpacity fallback). Both set every pixel's alpha to the same value, so fully-transparent pixels turn semi-opaque. GD doesn't have this problem because imagecopymerge blends without flattening the source alpha.

The fix scales the existing alpha instead of overwriting it: evaluateImage(EVALUATE_MULTIPLY, $alpha / 100, CHANNEL_ALPHA), after activating the alpha channel. Transparent stays transparent, opaque fades.

@mlocati

mlocati commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

👍

@mlocati mlocati merged commit a5a8f39 into php-imagine:develop Jun 3, 2026
21 checks passed
@nlemoine nlemoine deleted the fix/imagick-paste-alpha-transparency branch June 3, 2026 10:43
@nlemoine

nlemoine commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @mlocati!

@mlocati

mlocati commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks to you for these fixes and related tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants