-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Check images for true alpha transparency #8933
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
Check images for true alpha transparency #8933
Conversation
Because ImageMagick cannot save images with true alpha transparency in indexed PNG format, we need to check whether an image has true alpha transparency before telling ImageMagick to use the png8 (indexed) format. See https://core.trac.wordpress.org/ticket/63448
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
The additional comments are based on a suggestion from @SirLouen: https://core.trac.wordpress.org/ticket/63448#comment:89 (But I have added a bit more detail.)
| $is_png = false; | ||
| $is_indexed_png = false; | ||
| $is_indexed_png_with_alpha_channel = false; | ||
| $is_indexed_png_with_true_alpha_transparency = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a comment here indicating the meaning of true alpha channel (vs alpha channel)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a comment which explains the purpose of all these variables (and mentions what "true alpha" means here). Does that make things clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, thanks. I will update the language slightly.
| && defined( 'Imagick::CHANNEL_ALPHA' ) | ||
| ) { | ||
| $alpha_channel_depth = $this->image->getImageChannelDepth( Imagick::CHANNEL_ALPHA ); | ||
| if ( $alpha_channel_depth > 1 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this conditional can be included in the if block above
adamsilverstein
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Because ImageMagick cannot save images with true alpha transparency in indexed PNG format, we need to check whether an image has true alpha transparency before telling ImageMagick to use the png8 (indexed) format.
Trac ticket: https://core.trac.wordpress.org/ticket/63448
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.