[wp-trac] [WordPress Trac] #60910: WP 6.5: the code add support for AVIF image files in WordPress not work now

WordPress Trac noreply at wordpress.org
Wed Apr 3 17:55:17 UTC 2024


#60910: WP 6.5: the code add support for AVIF image files in WordPress not work now
--------------------------+------------------------------
 Reporter:  niktat        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  assigned
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:  6.5
 Severity:  normal        |  Resolution:
 Keywords:  close         |     Focuses:
--------------------------+------------------------------
Changes (by swissspidy):

 * keywords:  changes-requested needs-patch => close
 * component:  Formatting => Media


Old description:

> 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);

New description:

 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:

 {{{#!php
 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);
 }}}

--

Comment:

 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60910#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list