Make WordPress Core


Ignore:
Timestamp:
02/02/2024 05:46:50 PM (2 years ago)
Author:
adamsilverstein
Message:

Media: enable AVIF support.

Add support for uploading, editing and saving AVIF images when supported by the server.

Add 'image/avif' to supported mime types. Correctly identify AVIF images and sizes even when PHP doesn't support AVIF. Resize uploaded AVIF files (when supported) and use for front end markup.

Props adamsilverstein, lukefiretoss, ayeshrajans, navjotjsingh, Tyrannous, jb510, gregbenz, nickpagz, JavierCasares, mukesh27, yguyon, swissspidy.
Fixes #51228.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r57509 r57524  
    31183118                    'image/tiff' => 'tif',
    31193119                    'image/webp' => 'webp',
     3120                    'image/avif' => 'avif',
    31203121                )
    31213122            );
     
    32963297 * @since 4.7.1
    32973298 * @since 5.8.0 Added support for WebP images.
     3299 * @since 6.5.0 Added support for AVIF images.
    32983300 *
    32993301 * @param string $file Full path to the file.
     
    33503352            $mime = 'image/webp';
    33513353        }
     3354
     3355        /**
     3356         * Add AVIF fallback detection when image library doesn't support AVIF.
     3357         *
     3358         * Detection based on section 4.3.1 File-type box definition of the ISO/IEC 14496-12
     3359         * specification and the AV1-AVIF spec, see https://aomediacodec.github.io/av1-avif/v1.1.0.html#brands.
     3360         */
     3361
     3362         // Divide the header string into 4 byte groups.
     3363        $magic = str_split( $magic, 8 );
     3364
     3365        if (
     3366            isset( $magic[1] ) &&
     3367            isset( $magic[2] ) &&
     3368            'ftyp' === hex2bin( $magic[1] ) &&
     3369            ( 'avif' === hex2bin( $magic[2] ) || 'avis' === hex2bin( $magic[2] ) )
     3370        ) {
     3371            $mime = 'image/avif';
     3372        }
    33523373    } catch ( Exception $e ) {
    33533374        $mime = false;
     
    33893410            'tiff|tif'                     => 'image/tiff',
    33903411            'webp'                         => 'image/webp',
     3412            'avif'                         => 'image/avif',
    33913413            'ico'                          => 'image/x-icon',
    33923414            'heic'                         => 'image/heic',
     
    35103532        'ext2type',
    35113533        array(
    3512             'image'       => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp' ),
     3534            'image'       => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp', 'avif' ),
    35133535            'audio'       => array( 'aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ),
    35143536            'video'       => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ),
Note: See TracChangeset for help on using the changeset viewer.