Skip to content

Disable AVIF when ImageMagick does not support AVIF transparency#2540

Open
b1ink0 wants to merge 2 commits into
WordPress:trunkfrom
b1ink0:add/imagemagick-old-version-avif-transparency-loss-warning
Open

Disable AVIF when ImageMagick does not support AVIF transparency#2540
b1ink0 wants to merge 2 commits into
WordPress:trunkfrom
b1ink0:add/imagemagick-old-version-avif-transparency-loss-warning

Conversation

@b1ink0

@b1ink0 b1ink0 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2237

Relevant technical choices

This PR adds a helper function to detect whether the installed ImageMagick version is older than 6.9.12-68.

If the ImageMagick version does not fully support AVIF transparency, the AVIF option is disabled and a warning notice is shown on the settings screen.

See #2245 (comment) for why 6.9.12-68 was chosen, and see the discussion in PR #2245 for additional context.

Screenshots

Screenshot 2026-06-19 at 12 41 44 AM

Use of AI Tools

Used Codex to review the code and tests.

@b1ink0 b1ink0 added this to the webp-uploads n.e.x.t milestone Jun 18, 2026
@b1ink0 b1ink0 requested a review from adamsilverstein as a code owner June 18, 2026 19:13
@b1ink0 b1ink0 added [Type] Bug An existing feature is broken [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) labels Jun 18, 2026
@b1ink0 b1ink0 requested a review from westonruter June 18, 2026 19:13
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.92%. Comparing base (4fdf1e9) to head (d76f49b).

Files with missing lines Patch % Lines
plugins/webp-uploads/helper.php 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #2540      +/-   ##
==========================================
+ Coverage   69.64%   69.92%   +0.27%     
==========================================
  Files          90       90              
  Lines        7736     7753      +17     
==========================================
+ Hits         5388     5421      +33     
+ Misses       2348     2332      -16     
Flag Coverage Δ
multisite 69.92% <90.90%> (+0.27%) ⬆️
single 35.36% <0.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

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: @xtecneo, @wes-davis.

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: xtecneo, wes-davis.

Co-authored-by: b1ink0 <b1ink0@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: paulgibbs <djpaul@git.wordpress.org>
Co-authored-by: mindctrl <mindctrl@git.wordpress.org>

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

return false;
}

$supported = version_compare( $imagick_version, '6.9.12-68', '>=' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The -68 here. Is that compared right? In looking at https://www.php.net/manual/en/function.version-compare.php it seems this would cause the version to be considered less than 6.9.12-dev.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, it seems to work: https://3v4l.org/5NVBB

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added tests for different version strings in d76f49b.

$avif_supported = webp_uploads_mime_type_supported( 'image/avif' );
$webp_supported = webp_uploads_mime_type_supported( 'image/webp' );
$selected = webp_uploads_get_image_output_format();
$avif_supported = webp_uploads_mime_type_supported( 'image/avif' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should actually be returning false if webp_uploads_imagick_avif_transparency_supported() is returning false.

This is because the plugin will still default to AVIF otherwise at present, even when it is not fully supported:

// Check the selected output format.
$output_format = webp_uploads_mime_type_supported( 'image/avif' ) ? webp_uploads_get_image_output_format() : 'webp';
$default_transforms = array(
'image/jpeg' => array( 'image/' . $output_format ),
'image/webp' => array( 'image/' . $output_format ),
'image/avif' => array( 'image/avif' ),
'image/png' => array( 'image/' . $output_format ),
);

@b1ink0 b1ink0 Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If webp_uploads_mime_type_supported() returns false for AVIF when webp_uploads_imagick_avif_transparency_supported() fails, showing a separate settings warning specifically for AVIF transparency support would make the notice logic more complex.

If we are okay with showing the existing generic message that AVIF support is not available, then I think this is fine.

@westonruter you can take over the PR if we want to release today.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was thinking of something like "AVIF is supported, but not fully: transparency support is lacking."

@b1ink0 b1ink0 requested a review from westonruter June 18, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transparent backgrounds lost when converting to AVIF under certain conditions

2 participants