Skip to content

Fix the documented range of the background filter transparency - #1667

Merged
dbu merged 1 commit into
liip:2.xfrom
Amoifr:fix-1654-transparency-doc
Sep 11, 2026
Merged

dbu merged 1 commit into
liip:2.xfrom
Amoifr:fix-1654-transparency-doc

Conversation

@Amoifr

@Amoifr Amoifr commented Sep 10, 2026

Copy link
Copy Markdown
Contributor
Q A
Branch? 2.x
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets #1654
License MIT
Doc yes

@dbu you asked on #1654 whether the behaviour is the same across the Imagine drivers, since that decides between fixing the documentation and fixing the code. It is the same, so this fixes the documentation.

The reporter is right: 0 is the transparent end and 100 the opaque one, the opposite of what the page says. Omitting the option leaves the background opaque.

Measured on GD, running the filter and reading the alpha of a background pixel:

transparency resulting alpha
omitted 100 (opaque)
0 0 (fully transparent)
50 50
100 100 (opaque)

And the three drivers agree on the direction, since BackgroundFilterLoader hands the option straight to palette()->color($color, $alpha) and the semantics are Imagine's from there on:

  • GD: imagecolorallocatealpha(..., round(127 * (100 - $color->getAlpha()) / 100)), and GD's own alpha runs from 0 (opaque) to 127, so an alpha of 100 comes out opaque.
  • Imagick: $pixel->setColorValue(\Imagick::COLOR_ALPHA, $color->getAlpha() / 100), where the ImageMagick alpha channel is 1.0 for opaque.
  • Gmagick: throws alpha transparency is not supported for a value below 100 on a palette without alpha, so 100 is the opaque end there too.

So the value is an alpha, which reads as an opacity, despite the option being called transparency. I said as much on the page rather than only flipping the two words, since the name will keep surprising people.

The filter had no test at all, so the direction is pinned by one now. It uses the real GD driver, like GrayscaleFilterLoaderTest and the two FloatToIntCast... tests already do.

One thing I could not check and would rather not write into the documentation: Gmagick\Imagine::create() builds the canvas with $pixel->getcolor(false), without the alpha component, and only then calls setimagebackgroundcolor() with the full pixel. I do not have the extension to tell whether a partially transparent background actually comes out of it. If it does not, that is worth a note on the page, and you or someone with gmagick would know in a second.

…ency

The documentation had the range the wrong way round: 0 is the transparent end
and 100 the opaque one, and omitting the option leaves the background opaque.

The option is handed straight to the palette as the alpha of the background
color, so the semantics are Imagine's. The filter had no test, so the direction
is pinned by one now.

@dbu dbu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for clarifying this

@dbu
dbu merged commit d43fa18 into liip:2.x Sep 11, 2026
12 checks passed
@Amoifr
Amoifr deleted the fix-1654-transparency-doc branch October 18, 2026 10:01
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