diff --git a/plugins/webp-uploads/helper.php b/plugins/webp-uploads/helper.php
index c14b58d36f..99092b9df1 100644
--- a/plugins/webp-uploads/helper.php
+++ b/plugins/webp-uploads/helper.php
@@ -514,3 +514,40 @@ function webp_uploads_get_attachment_file_mime_type( int $attachment_id, string
$mime_type = $filetype['type'] ?? get_post_mime_type( $attachment_id );
return is_string( $mime_type ) ? $mime_type : '';
}
+
+/**
+ * Checks if Imagick has AVIF transparency support.
+ *
+ * @since n.e.x.t
+ *
+ * @param string|null $version Optional Imagick version string. If not provided, the version will be retrieved from the Imagick class.
+ * @return bool True if Imagick has AVIF transparency support, false otherwise.
+ */
+function webp_uploads_imagick_avif_transparency_supported( ?string $version = null ): bool {
+ $supported = false;
+ $imagick_version = $version;
+
+ if ( null === $imagick_version && extension_loaded( 'imagick' ) && class_exists( 'Imagick' ) ) {
+ $imagick_version = Imagick::getVersion();
+ $imagick_version = $imagick_version['versionString'];
+ }
+
+ if ( null !== $imagick_version && '' !== $imagick_version && (bool) preg_match( '/\d+(?:\.\d+)+(?:-\d+)?/', $imagick_version, $matches ) ) {
+ $imagick_version = $matches[0];
+ }
+
+ if ( null === $imagick_version || '' === $imagick_version ) {
+ return false;
+ }
+
+ $supported = version_compare( $imagick_version, '6.9.12-68', '>=' );
+
+ /**
+ * Filters whether Imagick has AVIF transparency support.
+ *
+ * @since n.e.x.t
+ *
+ * @param bool $supported Whether AVIF transparency is supported.
+ */
+ return (bool) apply_filters( 'webp_uploads_imagick_avif_transparency_supported', $supported );
+}
diff --git a/plugins/webp-uploads/settings.php b/plugins/webp-uploads/settings.php
index 80d48bdcc0..12de37042e 100644
--- a/plugins/webp-uploads/settings.php
+++ b/plugins/webp-uploads/settings.php
@@ -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' );
+ $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,7 +171,7 @@ 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';
@@ -178,7 +179,7 @@ function webp_uploads_generate_avif_webp_setting_callback(): void {
?>