Make WordPress Core

Opened 4 weeks ago

Last modified 3 weeks ago

#60910 assigned defect (bug)

WP 6.5: the code add support for AVIF image files in WordPress not work now

Reported by: niktat's profile niktat Owned by: adamsilverstein's profile adamsilverstein
Milestone: 6.6 Priority: normal
Severity: normal Version: 6.5
Component: Media Keywords: close reporter-feedback avif
Focuses: Cc:

Description (last modified by swissspidy)

Using AVIF images in WordPress even after adding code that supports AVIF image files in WordPress by adding the AVIF and AVIFS MIME types to the function.php file is not currently possible. This was possible in previous versions.

You wrote: AVIF images work like any other image format in WordPress, with a few important notes:
AVIF in WordPress depends on support in your web server’s image processing library (WordPress has built-in support for both Imagick and LibGD for image processing). You can check for AVIF support in wp-admin by visiting Tools -> Site Health, clicking the “Info” tab and expanding the “Media Handling” section, then finally looking for “AVIF” in the list of supported formats.

AVIF is absent there.

Please fix it!

FOR your information:

function add_avif_to_upload_mimes($mime_types) {
    $mime_types['avif'] = 'image/avif';
    $mime_types['avifs'] = 'image/avif-sequence';
    return $mime_types;
}

add_filter('upload_mimes', 'add_avif_to_upload_mimes');

// Enable preview / thumbnail for avif image files.
function avif_is_displayable($result, $path) {
    if ($result === false) {
        $displayable_image_types = array( IMAGETYPE_JPC, IMAGETYPE_JP2, IMAGETYPE_JPX );
        $info = @getimagesize( $path );
        if (empty($info)) {
            $result = false;
        } elseif (!in_array($info[2], $displayable_image_types)) {
            $result = false;
        } else {
            $result = true;
        }
    }
    return $result;
}
add_filter('file_is_displayable_image', 'avif_is_displayable', 10, 2);

Attachments (1)

Screenshot-2024-04-03-at-19.46.02.jpg (203.2 KB) - added by niktat 4 weeks ago.

Download all attachments as: .zip

Change History (12)

#1 @swissspidy
4 weeks ago

  • Component changed from Formatting to Media
  • Description modified (diff)
  • Keywords close added; changes-requested needs-patch removed

Hi there and welcome to WordPress Trac!

As the note says, AVIF in WordPress depends on support in your web server’s image processing library

If AVIF is not in the "GD supported file formats" list, it means your version of GD does not support AVIF.

AVIF support in GD is only possible in PHP 8.1 or newer, but only if the GD extension is compiled with AVIF support. It depends on libavif package, which may not be available in default repositories of older operating system versions.

In your case, that means:

  • Either you are not using PHP 8.1+, or
  • You are using PHP 8.1+ but GD has not been compiled with AVIF support

Either way, that means you should reach out to your hosting provider to inquire about adding AVIF support on your server.

They could possibly achieve this also through setting up ImageMagick so that WordPress uses ImageMagick instead of GD for image processing.

#2 @niktat
4 weeks ago

Thanks for quick answer.
I have reached out to our hosting provider to inquire about adding AVIF support on our server.

#3 @niktat
4 weeks ago

Greetings.
This is answer from hosting provider:
...At this time, this is not supported in the libraries that cPanel offers through EasyApache. There is an open feature request here that you can vote and comment on if this is a feature you would like to see added:
https://features.cpanel.net/c/84-avif-support-for-php-8-1-8-2-and-8-3
https://support.cpanel.net/hc/en-us/articles/4418491676823-AVIF-support-for-GD-in-PHP-8-1

For this reason, my question is: Why did you remove the ability to use AVIF images in WordPress after adding code that supports AVIF image files in WordPress by adding the AVIF and AVIFS MIME types to the function.php file? See the code in my ticket. This was possible in previous versions, even the oldest ones.

This ticket was mentioned in Slack in #core-media by azaozz. View the logs.


4 weeks ago

#5 @adamsilverstein
4 weeks ago

  • Keywords reporter-feedback added

Using AVIF images in WordPress even after adding code that supports AVIF image files in WordPress by adding the AVIF and AVIFS MIME types to the function.php file is not currently possible. This was possible in previous versions.

Hi @niktat thanks for the bug report.

Once you add the code in your description, can you describe exactly how you are trying to use the AVIF image, and what isn't working now that previously did?

Do you get an error trying to upload AVIF images to the media library? Or are you inserting the image directly in the media editor? Having a description of the steps required to reproduce the issue would be helpful to troubleshooting and figuring out how to improve or fix.

One thing worth noting is that without AVIF support on your server, even if you are able to upload AVIFs, WordPress will be unable to create the sub-sized images it typically uses for the srcset part of the image tag. This tag makes images responsive, so the browser can serve smaller images to mobile clients for example.

There is an open feature request here that you can vote and comment on if this is a feature you would like to see added

Thanks, I upvoted and looks like they are planning to add as of a recent comment so maybe you will have support soon.

#6 @niktat
4 weeks ago

Hi @adamsilverstein.

Once I added the code to support AVIF image files in WordPress by adding the AVIF and AVIFS MIME types to function.php, I could load and delete the AVIF file as usual. After updating WP to 6.5 I can no longer do this. I'm not sure, but it seems to me that I didn't get any error report - just nothing happened after trying to download and delete the AVIF file.


#8 @adamsilverstein
4 weeks ago

  • Keywords avif added

After updating WP to 6.5 I can no longer do this

I will try to reproduce on my end.

@niktat some questions:

  • are you blocked from uploading new AVIF images since 6.5?
  • how are you trying to upload the AVIF images?

#9 @niktat
4 weeks ago

Just install WP 6.4.3 and add code as I noted above. Then update it to 6.5 and you will can't use the code more.

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


3 weeks ago

#11 @adamsilverstein
3 weeks ago

  • Milestone changed from Awaiting Review to 6.6
  • Owner set to adamsilverstein
Note: See TracTickets for help on using tickets.