Skip to content

Conversation

olivervogel
Copy link
Contributor

For the calls of the Background bg manipulator Intervention Image has already an own method blendTransparency() to set the background color of the image.

This patch simplifies the Background::class manipulator in that way and replaces the manual individual steps with the mentioned method.

Intervention Image has already a method `blendTransparency()` to do this
taks. It is therefore not necessary to carry out the individual steps
manually.
@ADmad ADmad merged commit de49c31 into thephpleague:master Mar 21, 2025
7 checks passed
@ADmad
Copy link
Collaborator

ADmad commented Mar 21, 2025

While looking into this I found that setting bg doesn't work when for e.g. using fit=fill and the using w and h larger than the original image dimensions. The extra area if always white since the default background color for Image::pad() is ffffff. Before merging this change, changing the background color to 'ffffff00' for Image::pad() fixed this issue but after merging this the background color is "skewed".

Before merging this PR using bg=blue I get
k1
After this merge
k2

@ADmad
Copy link
Collaborator

ADmad commented Mar 21, 2025

Problem seems to occur only when blue color is involved. If I use red or green the results appear same before and after this patch.

@olivervogel
Copy link
Contributor Author

I think the definition of the default background color in Image::pad() and other methods could have been implemented more logically in Intervention Image. Unfortunately a breaking change.

See Intervention/image#1391 (comment)

@ADmad
Copy link
Collaborator

ADmad commented Mar 22, 2025

I think the definition of the default background color in Image::pad() and other methods could have been implemented more logically in Intervention Image.

Yes, ffffff does not seem like a good default, null or transparent would be better.

The problem I described above only occurs when using imagick, not gd. So to summarize, when using imagick and blue as the blending color, the resulting background color is off (PHP 8.4 and imagick 3.7.0 ).

@olivervogel
Copy link
Contributor Author

The problem I described above only occurs when using imagick, not gd. So to summarize, when using imagick and blue as the blending color, the resulting background color is off (PHP 8.4 and imagick 3.7.0 ).

I'm not sure but maybe it's better to revert my changes.

@ADmad
Copy link
Collaborator

ADmad commented Mar 22, 2025

I'll try to look into it a bit more over the weekend and then decide. Will also try to submit a test case / minimal example for the issue.

@ADmad
Copy link
Collaborator

ADmad commented Mar 22, 2025

I am going to revert this. The blending color is only used when outputting to image format which does not support transparency. But when bg is specified that color should replace the transparent area.

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.

3 participants