Skip to content

Commit

Permalink
Add AVIF support
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsilverstein committed Jun 13, 2023
1 parent 0bfc842 commit b96bb09
Show file tree
Hide file tree
Showing 19 changed files with 961 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/js/_enqueues/vendor/plupload/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@ jQuery( document ).ready( function( $ ) {
wpQueueError( pluploadL10n.noneditable_image );
up.removeFile( file );
return;
} else if ( file.type === 'image/avif' && up.settings.avif_upload_error ) {
// Disallow uploading of AVIF images if the server cannot edit them.
wpQueueError( pluploadL10n.noneditable_image );
up.removeFile( file );
return;
}

fileQueued( file );
Expand Down
5 changes: 5 additions & 0 deletions src/js/_enqueues/vendor/plupload/wp-plupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ window.wp = window.wp || {};
error( pluploadL10n.noneditable_image, {}, file, 'no-retry' );
up.removeFile( file );
return;
} else if ( file.type === 'image/avif' && up.settings.avif_upload_error ) {
// Disallow uploading of AVIF images if the server cannot edit them.
error( pluploadL10n.noneditable_image, {}, file, 'no-retry' );
up.removeFile( file );
return;
}

// Generate attributes for a new `Attachment` model.
Expand Down
5 changes: 3 additions & 2 deletions src/js/_enqueues/vendor/thickbox/thickbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
baseURL = url;
}

var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$|\.webp$/;
var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$|\.webp$|\.avif$/;
var urlType = baseURL.toLowerCase().match(urlString);

if(urlType == '.jpg' ||
urlType == '.jpeg' ||
urlType == '.png' ||
urlType == '.gif' ||
urlType == '.bmp' ||
urlType == '.webp'
urlType == '.webp' ||
urlType == '.avif'
){//code to show images

TB_PrevCaption = "";
Expand Down
2 changes: 1 addition & 1 deletion src/js/media/controllers/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar
isImageAttachment: function( attachment ) {
// If uploading, we know the filename but not the mime type.
if ( attachment.get('uploading') ) {
return /\.(jpe?g|png|gif|webp)$/i.test( attachment.get('filename') );
return /\.(jpe?g|png|gif|webp|avif)$/i.test( attachment.get('filename') );
}

return attachment.get('type') === 'image';
Expand Down
11 changes: 11 additions & 0 deletions src/wp-admin/includes/image-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ function wp_stream_image( $image, $mime_type, $attachment_id ) {
return imagewebp( $image, null, 90 );
}
return false;
case 'image/avif':
if ( function_exists( 'imageavif' ) ) {
header( 'Content-Type: image/avif' );
return imageavif( $image, null, 90 );
}
return false;
default:
return false;
}
Expand Down Expand Up @@ -491,6 +497,11 @@ function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
return imagewebp( $image, $filename );
}
return false;
case 'image/avif':
if ( function_exists( 'imageavif' ) ) {
return imageavif( $image, $filename );
}
return false;
default:
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/wp-admin/includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,11 @@ function media_upload_form( $errors = null ) {
$plupload_init['webp_upload_error'] = true;
}

// Check if AVIF images can be edited.
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) {
$plupload_init['avif_upload_error'] = true;
}

/**
* Filters the default Plupload settings.
*
Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/includes/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,7 @@ function populate_network_meta( $network_id, array $meta = array() ) {
'png',
'gif',
'webp',
'avif',
// Video.
'mov',
'avi',
Expand Down

0 comments on commit b96bb09

Please sign in to comment.