Skip to content

Commit 37c0bf9

Browse files
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. Built from https://develop.svn.wordpress.org/trunk@57524 git-svn-id: https://core.svn.wordpress.org/trunk@57025 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 51b1f98 commit 37c0bf9

25 files changed

Lines changed: 975 additions & 17 deletions

wp-admin/includes/image-edit.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ function wp_stream_image( $image, $mime_type, $attachment_id ) {
390390
return imagewebp( $image, null, 90 );
391391
}
392392
return false;
393+
case 'image/avif':
394+
if ( function_exists( 'imageavif' ) ) {
395+
header( 'Content-Type: image/avif' );
396+
return imageavif( $image, null, 90 );
397+
}
398+
return false;
393399
default:
394400
return false;
395401
}
@@ -494,6 +500,11 @@ function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
494500
return imagewebp( $image, $filename );
495501
}
496502
return false;
503+
case 'image/avif':
504+
if ( function_exists( 'imageavif' ) ) {
505+
return imageavif( $image, $filename );
506+
}
507+
return false;
497508
default:
498509
return false;
499510
}

wp-admin/includes/image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ function file_is_valid_image( $path ) {
10061006
* @return bool True if suitable, false if not suitable.
10071007
*/
10081008
function file_is_displayable_image( $path ) {
1009-
$displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP );
1009+
$displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP, IMAGETYPE_AVIF );
10101010

10111011
$info = wp_getimagesize( $path );
10121012
if ( empty( $info ) ) {

wp-admin/includes/media.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,11 @@ function media_upload_form( $errors = null ) {
21982198
$plupload_init['webp_upload_error'] = true;
21992199
}
22002200

2201+
// Check if AVIF images can be edited.
2202+
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) {
2203+
$plupload_init['avif_upload_error'] = true;
2204+
}
2205+
22012206
/**
22022207
* Filters the default Plupload settings.
22032208
*

wp-admin/includes/schema.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,7 @@ function populate_network_meta( $network_id, array $meta = array() ) {
12501250
'png',
12511251
'gif',
12521252
'webp',
1253+
'avif',
12531254
// Video.
12541255
'mov',
12551256
'avi',

0 commit comments

Comments
 (0)