Make WordPress Core

Opened 6 months ago

Closed 4 months ago

Last modified 4 months ago

#60910 closed defect (bug) (fixed)

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: Priority: normal
Severity: normal Version: 6.5
Component: Media Keywords: close reporter-feedback avif has-patch
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 6 months ago.

Download all attachments as: .zip

Change History (21)

#1 @swissspidy
6 months 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
6 months ago

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

#3 @niktat
6 months 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.


6 months ago

#5 @adamsilverstein
6 months 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
6 months 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
6 months 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
6 months 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.


6 months ago

#11 @adamsilverstein
6 months ago

  • Milestone changed from Awaiting Review to 6.6
  • Owner set to adamsilverstein

This ticket was mentioned in PR #6627 on WordPress/wordpress-develop by @adamsilverstein.


4 months ago
#12

  • Keywords has-patch added

Prevents a false positive for AVIF format support when IMG_AVIF is defined, but the imageavif function is not. See https://github.com/php/php-src/issues/12019

Trac ticket: https://core.trac.wordpress.org/ticket/60910

#13 follow-up: @adamsilverstein
4 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 58305:

Media: improve GD support detection for AVIF.
Fix an issue where the GD image library falsely reports supporting the AVIF format, when support is actually missing. Add an additional function check to ensure AVIF support is really available.
Props niktat, adamsilverstein.
Fixes #60910

#15 in reply to: ↑ 13 @skithund
4 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Replying to adamsilverstein:

In 58305:
Fix an issue where the GD image library falsely reports supporting the AVIF format

This (checking that imageavif exists) doesn't fix the problem. AVIF functions are available, even though AVIF support isn't there.

See my comments on #60628

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


4 months ago

#17 @adamsilverstein
4 months ago

This (checking that imageavif exists) doesn't fix the problem. AVIF functions are available, even though AVIF support isn't there.

Thanks, this did fix the issue in my testing, but quite possible I missed something in the process.

#18 @adamsilverstein
4 months ago

  • Milestone 6.6 deleted
  • Resolution set to wontfix
  • Status changed from reopened to closed

closing in favor of #60628

#19 @sabernhardt
4 months ago

This ticket has a commit, so I do not think that 'wontfix' is appropriate. Changing the resolution to 'duplicate' might be better, but that is probably not the best option either.

Last edited 4 months ago by sabernhardt (previous) (diff)

#20 @swissspidy
4 months ago

  • Resolution changed from wontfix to fixed
Note: See TracTickets for help on using tickets.