mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 21:00:21 +00:00
Images: enable WebP support.
Add support for uploading, editing and saving WebP images when supported by the server. Add 'image/webp' to supported mime types. Correctly identify WebP images and sizes even when PHP doesn't support WebP. Resize uploaded WebP files (when supported) and use for front end markup. Props markoheijne, blobfolio, Clorith, joemcgill, atjn, desrosj, spacedmonkey, marylauc, mikeschroder, hellofromtonya, flixos90. Fixes #35725. git-svn-id: https://develop.svn.wordpress.org/trunk@50810 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2886,6 +2886,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
|
||||
'image/gif' => 'gif',
|
||||
'image/bmp' => 'bmp',
|
||||
'image/tiff' => 'tif',
|
||||
'image/webp' => 'webp',
|
||||
)
|
||||
);
|
||||
|
||||
@@ -3063,6 +3064,35 @@ function wp_get_image_mime( $file ) {
|
||||
} else {
|
||||
$mime = false;
|
||||
}
|
||||
|
||||
if ( false !== $mime ) {
|
||||
return $mime;
|
||||
}
|
||||
|
||||
$handle = fopen( $file, 'rb' );
|
||||
if ( false === $handle ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$magic = fread( $handle, 12 );
|
||||
if ( false === $magic ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add WebP fallback detection when image library doesn't support WebP.
|
||||
// Note: detection values come from LibWebP, see
|
||||
// https://github.com/webmproject/libwebp/blob/master/imageio/image_dec.c#L30
|
||||
$magic = bin2hex( $magic );
|
||||
if (
|
||||
// RIFF.
|
||||
( 0 === strpos( $magic, '52494646' ) ) &&
|
||||
// WEBP.
|
||||
( 16 === strpos( $magic, '57454250' ) )
|
||||
) {
|
||||
$mime = 'image/webp';
|
||||
}
|
||||
|
||||
fclose( $handle );
|
||||
} catch ( Exception $e ) {
|
||||
$mime = false;
|
||||
}
|
||||
@@ -3101,6 +3131,7 @@ function wp_get_mime_types() {
|
||||
'png' => 'image/png',
|
||||
'bmp' => 'image/bmp',
|
||||
'tiff|tif' => 'image/tiff',
|
||||
'webp' => 'image/webp',
|
||||
'ico' => 'image/x-icon',
|
||||
'heic' => 'image/heic',
|
||||
// Video formats.
|
||||
@@ -3222,7 +3253,7 @@ function wp_get_ext_types() {
|
||||
return apply_filters(
|
||||
'ext2type',
|
||||
array(
|
||||
'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic' ),
|
||||
'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp' ),
|
||||
'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ),
|
||||
'video' => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ),
|
||||
'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf' ),
|
||||
|
||||
Reference in New Issue
Block a user