Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GD's alpha consistent with other engines #10

Closed
wants to merge 1 commit into from
Closed

Make GD's alpha consistent with other engines #10

wants to merge 1 commit into from

Conversation

SteveMarshall
Copy link

GD expects alpha values to be 0-127, with 0 being opaque and 127 being transparent (7-bit little-endian). Everything else uses 0 as transparent and 255 as opaque (8-bit big-endian). This change converts 8-bit big-endian inputs to 7-bit little-endian when used by GD.

This change will be backwards incompatible, and may confuse people who already know GD handles alpha this way, but it makes ngx_small_light more consistent to use (and means users can swap engines more easily).

This fixes #9.

GD expects alpha values to be 0-127, with 0 being opaque and 127 being
transparent (7-bit little-endian). Everything else uses 0 as
transparent and 255 as opaque (8-bit big-endian). This change converts
8-bit big-endian inputs to 7-bit little-endian when used by GD.

This change will be backwards incompatible, and may confuse people who
already know GD handles alpha this way, but it makes ngx_small_light
more consistent to use (and means users can swap engines more easily).
@cubicdaiya
Copy link
Owner

Hi, @SteveMarshall

Tnanks for submmitting your patch.

Though I checked your patch and recognized GD's alpha channel problem,
But It looks not good to me after applying your patch except alpha-value is 0x00 or 0xff.
For example, e=gd is not consistent with other engines when alpha-value is 0xab.

And I don't know how to convert an alpha-value which range is 0255 to which alpha-value which range is 0127 and inverted correctly.

Do you have any idea?

@SteveMarshall
Copy link
Author

I think the inconsistency between engines is actually because the other engines aren't using the alpha channel properly. When I use cc=ff000000 with ImageMagick, it shows the canvas as red instead of transparent, black, or white (I’d expect one of those).

With e=gd and my patch, cc=ff000000 shows black (GD's default background colour), and with cc=ff0000ab, it shows red blended with black, which I think is the correct behaviour.

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.

GD image alpha is inverted
2 participants