Save every new uploaded image as AVIF :
function filter_image_editor_output_format( $formats ) {
$formats['image/jpeg'] = 'image/avif';
return $formats;
}
add_filter( 'image_editor_output_format', 'filter_image_editor_output_format' );
To preserve gif animations : webpffmpeg -i ./input.gif -vcodec webp -pix_fmt yuva420p ./output.webp
Source : https://make.wordpress.org/core/2024/02/23/wordpress-6-5-adds-avif-support/