Skip to content

Conversation

@westonruter
Copy link
Member

@westonruter westonruter commented May 14, 2024

Fixes #1214

By default ImagickPixel::getColor() returns an array with the 4th alpha array item being a binary 0 or 1. This doesn't work when the image has partial transparency. To detect that, you have to pass a $normalized parameter to this method, either 1 (to return a 0.0-1.0 float) or 2 (to return a 0-1255 int). So this passes 2 so we can correctly compare if the alpha value is greater than 0.

This PR also improves the test cases by removing duplicate tests and ensuring that the GD and Imagick code paths are both tested. Previously it was doing the same tests twice for GD since the tests weren't forcing either the GD or Imagick code path. As part of this, the Imagick tests now show up as being skipped since wp-env appears to have a misconfigured Imagick as detailed by @thelovekesh.

@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Image Placeholders Issues for the Image Placeholders plugin (formerly Dominant Color Images) labels May 14, 2024
@github-actions
Copy link

github-actions bot commented May 14, 2024

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 props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @JacobDB.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: JacobDB.

Co-authored-by: westonruter <[email protected]>
Co-authored-by: thelovekesh <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

for ( $y = 0; $y < $h; $y++ ) {
$pixel = $this->image->getImagePixelColor( $x, $y );
$color = $pixel->getColor();
$color = $pixel->getColor( 2 );
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the crux of the fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because of #1215 (comment), however, this is not currently getting tested in PHPUnit in wp-env.

@westonruter
Copy link
Member Author

I discovered that the tests were not testing both of the Imagick and GD codepaths. It was rather just testing the GD codepath twice, since it was letting WP select the implementation that was available in both the GD and Imagick test cases.

As part of this, I found that Imagick seems to not be configured properly in wp-env because wp_image_editor_supports() is returning false for every image when testing Imagick. @thelovekesh was this what you discovered as well?

@westonruter westonruter changed the title Fix Imagick detecting partial transparency by passing normalized=2 Fix Imagick detecting partial transparency May 14, 2024
@thelovekesh
Copy link
Member

Yes, @westonruter. I have explained it in - #1013 (comment) and #1013 (comment)

@westonruter westonruter merged commit d50ebb8 into trunk May 16, 2024
@westonruter westonruter deleted the fix/imagick-partial-transparency branch May 16, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Image Placeholders Issues for the Image Placeholders plugin (formerly Dominant Color Images) [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Images with partial transpency return "false" for "has-transparency"

3 participants