-
Notifications
You must be signed in to change notification settings - Fork 152
Disable AVIF when ImageMagick does not support AVIF transparency #2540
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -153,9 +153,10 @@ static function (): void { | |||||||||||||||||||
| */ | ||||||||||||||||||||
| function webp_uploads_generate_avif_webp_setting_callback(): void { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| $selected = webp_uploads_get_image_output_format(); | ||||||||||||||||||||
| $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' ); | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should actually be returning This is because the plugin will still default to AVIF otherwise at present, even when it is not fully supported: performance/plugins/webp-uploads/helper.php Lines 30 to 38 in 4fdf1e9
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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." |
||||||||||||||||||||
| $avif_transparency_supported = webp_uploads_imagick_avif_transparency_supported(); | ||||||||||||||||||||
| $webp_supported = webp_uploads_mime_type_supported( 'image/webp' ); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // If neither format is support, the entire field is not shown. | ||||||||||||||||||||
| if ( ! $avif_supported && ! $webp_supported ) { | ||||||||||||||||||||
|
|
@@ -170,15 +171,15 @@ function webp_uploads_generate_avif_webp_setting_callback(): void { | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // If only one of the two formats is supported, the dropdown defaults to that type and the other type is disabled. | ||||||||||||||||||||
| if ( ! $avif_supported && 'avif' === $selected ) { | ||||||||||||||||||||
| if ( ! ( $avif_supported && $avif_transparency_supported ) && 'avif' === $selected ) { | ||||||||||||||||||||
| $selected = 'webp'; | ||||||||||||||||||||
| } elseif ( ! $webp_supported && 'webp' === $selected ) { | ||||||||||||||||||||
| $selected = 'avif'; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| ?> | ||||||||||||||||||||
| <select name="perflab_modern_image_format" id="perflab_modern_image_format" aria-describedby="perflab_modern_image_format_description"> | ||||||||||||||||||||
| <option value="webp"<?php selected( 'webp', $selected ); ?><?php disabled( ! $webp_supported ); ?>><?php esc_html_e( 'WebP', 'webp-uploads' ); ?></option> | ||||||||||||||||||||
| <option value="avif"<?php selected( 'avif', $selected ); ?><?php disabled( ! $avif_supported ); ?>><?php esc_html_e( 'AVIF', 'webp-uploads' ); ?></option> | ||||||||||||||||||||
| <option value="avif"<?php selected( 'avif', $selected ); ?><?php disabled( ! ( $avif_supported && $avif_transparency_supported ) ); ?>><?php esc_html_e( 'AVIF', 'webp-uploads' ); ?></option> | ||||||||||||||||||||
| </select> | ||||||||||||||||||||
| <label for="perflab_modern_image_format"> | ||||||||||||||||||||
| <?php esc_html_e( 'Generate images in this format', 'webp-uploads' ); ?> | ||||||||||||||||||||
|
|
@@ -201,6 +202,13 @@ function webp_uploads_generate_avif_webp_setting_callback(): void { | |||||||||||||||||||
| <p><?php esc_html_e( 'WebP support can only be enabled by your hosting provider, so contact them for more information.', 'webp-uploads' ); ?></p> | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| <?php endif; ?> | ||||||||||||||||||||
| <?php if ( $avif_supported && ! $avif_transparency_supported ) : ?> | ||||||||||||||||||||
| <br /> | ||||||||||||||||||||
| <div class="notice notice-warning inline"> | ||||||||||||||||||||
| <p><b><?php esc_html_e( 'AVIF transparency support is not available.', 'webp-uploads' ); ?></b></p> | ||||||||||||||||||||
| <p><?php esc_html_e( 'Current ImageMagick version does not support transparent AVIF images, so contact your hosting provider for more information.', 'webp-uploads' ); ?></p> | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| <?php endif; ?> | ||||||||||||||||||||
| <?php | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
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.
The
-68here. 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 than6.9.12-dev.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.
Well, it seems to work: https://3v4l.org/5NVBB
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.
Added tests for different version strings in d76f49b.