Ticket #35725: 35725.4.diff
File 35725.4.diff, 25.9 KB (added by , 4 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php index a6f4a21e45..02f8c5ae8b 100644
function wp_ajax_crop_image() { 3926 3926 $parent_url = wp_get_attachment_url( $attachment_id ); 3927 3927 $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); 3928 3928 3929 $size = wp_get imagesize( $cropped );3929 $size = wp_get_image_size( $cropped ); 3930 3930 $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; 3931 3931 3932 3932 $object = array( -
src/wp-admin/includes/class-custom-image-header.php
diff --git src/wp-admin/includes/class-custom-image-header.php src/wp-admin/includes/class-custom-image-header.php index 76eddff973..c5c4cccf76 100644
endif; 791 791 } 792 792 793 793 if ( file_exists( $file ) ) { 794 list( $width, $height, $type, $attr ) = wp_get imagesize( $file );794 list( $width, $height, $type, $attr ) = wp_get_image_size( $file ); 795 795 } else { 796 796 $data = wp_get_attachment_metadata( $attachment_id ); 797 797 $height = isset( $data['height'] ) ? $data['height'] : 0; … … endif; 1223 1223 $parent_url = wp_get_attachment_url( $parent->ID ); 1224 1224 $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); 1225 1225 1226 $size = wp_get imagesize( $cropped );1226 $size = wp_get_image_size( $cropped ); 1227 1227 $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; 1228 1228 1229 1229 $object = array( -
src/wp-admin/includes/class-wp-site-icon.php
diff --git src/wp-admin/includes/class-wp-site-icon.php src/wp-admin/includes/class-wp-site-icon.php index 9aff0f2a8d..151a88fbb3 100644
class WP_Site_Icon { 87 87 $parent_url = wp_get_attachment_url( $parent->ID ); 88 88 $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); 89 89 90 $size = wp_get imagesize( $cropped );90 $size = wp_get_image_size( $cropped ); 91 91 $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; 92 92 93 93 $object = array( -
src/wp-admin/includes/image-edit.php
diff --git src/wp-admin/includes/image-edit.php src/wp-admin/includes/image-edit.php index ce80a69ad5..416f69c998 100644
function wp_stream_image( $image, $mime_type, $attachment_id ) { 306 306 case 'image/gif': 307 307 header( 'Content-Type: image/gif' ); 308 308 return imagegif( $image ); 309 case 'image/webp': 310 if ( function_exists( 'imagewebp' ) ) { 311 header( 'Content-Type: image/webp' ); 312 return imagewebp( $image, null, 90 ); 313 } 314 return false; 309 315 default: 310 316 return false; 311 317 } … … function wp_save_image_file( $filename, $image, $mime_type, $post_id ) { 391 397 return imagepng( $image, $filename ); 392 398 case 'image/gif': 393 399 return imagegif( $image, $filename ); 400 case 'image/webp': 401 if ( function_exists( 'imagewebp' ) ) { 402 return imagewebp( $image, null, apply_filters( 'jpeg_quality', 90, 'edit_image' ) ); 403 } 404 return false; 394 405 default: 395 406 return false; 396 407 } -
src/wp-admin/includes/image.php
diff --git src/wp-admin/includes/image.php src/wp-admin/includes/image.php index 56b9c0a36f..839592ab86 100644
function wp_get_missing_image_subsizes( $attachment_id ) { 93 93 // Use the originally uploaded image dimensions as full_width and full_height. 94 94 if ( ! empty( $image_meta['original_image'] ) ) { 95 95 $image_file = wp_get_original_image_path( $attachment_id ); 96 $imagesize = wp_get imagesize( $image_file );96 $imagesize = wp_get_image_size( $image_file ); 97 97 } 98 98 99 99 if ( ! empty( $imagesize ) ) { … … function _wp_image_meta_replace_original( $saved_data, $original_file, $image_me 224 224 * @return array The image attachment meta data. 225 225 */ 226 226 function wp_create_image_subsizes( $file, $attachment_id ) { 227 $imagesize = wp_get imagesize( $file );227 $imagesize = wp_get_image_size( $file ); 228 228 229 229 if ( empty( $imagesize ) ) { 230 230 // File is not an image. … … function wp_generate_attachment_metadata( $attachment_id, $file ) { 517 517 case 'image/png': 518 518 $ext = '.png'; 519 519 break; 520 case 'image/webp': 521 $ext = '.webp'; 522 break; 520 523 } 521 524 $basename = str_replace( '.', '-', wp_basename( $file ) ) . '-image' . $ext; 522 525 $uploaded = wp_upload_bits( $basename, '', $metadata['image']['data'] ); … … function wp_read_image_metadata( $file ) { 687 690 return false; 688 691 } 689 692 690 list( , , $image_type ) = wp_get imagesize( $file );693 list( , , $image_type ) = wp_get_image_size( $file ); 691 694 692 695 /* 693 696 * EXIF contains a bunch of data we'll probably never need formatted in ways … … function wp_read_image_metadata( $file ) { 716 719 * as caption, description etc. 717 720 */ 718 721 if ( is_callable( 'iptcparse' ) ) { 719 wp_get imagesize( $file, $info );722 wp_get_image_size( $file, $info ); 720 723 721 724 if ( ! empty( $info['APP13'] ) ) { 722 725 if ( … … function wp_read_image_metadata( $file ) { 899 902 * @return bool True if valid image, false if not valid image. 900 903 */ 901 904 function file_is_valid_image( $path ) { 902 $size = wp_get imagesize( $path );905 $size = wp_get_image_size( $path ); 903 906 return ! empty( $size ); 904 907 } 905 908 … … function file_is_valid_image( $path ) { 914 917 function file_is_displayable_image( $path ) { 915 918 $displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO ); 916 919 917 $info = wp_get imagesize( $path );920 $info = wp_get_image_size( $path ); 918 921 if ( empty( $info ) ) { 919 922 $result = false; 920 923 } elseif ( ! in_array( $info[2], $displayable_image_types, true ) ) { … … function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) { 962 965 case 'image/gif': 963 966 $image = imagecreatefromgif( $filepath ); 964 967 break; 968 case 'image/webp': 969 if ( function_exists( 'imagecreatefromwebp' ) ) { 970 $image = imagecreatefromwebp( $filepath ); 971 } else { 972 $image = false; 973 } 974 break; 965 975 default: 966 976 $image = false; 967 977 break; -
src/wp-admin/includes/media.php
diff --git src/wp-admin/includes/media.php src/wp-admin/includes/media.php index 93d850d606..12b079ac69 100644
function wp_media_upload_handler() { 982 982 function media_sideload_image( $file, $post_id = 0, $desc = null, $return = 'html' ) { 983 983 if ( ! empty( $file ) ) { 984 984 985 $allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif' );985 $allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'webp' ); 986 986 987 987 /** 988 988 * Filters the list of allowed file extensions when sideloading an image from a URL. -
src/wp-admin/includes/schema.php
diff --git src/wp-admin/includes/schema.php src/wp-admin/includes/schema.php index a59c7c36ce..6f528f2288 100644
We hope you enjoy your new site. Thanks! 1215 1215 'jpeg', 1216 1216 'png', 1217 1217 'gif', 1218 'webp', 1218 1219 // Video. 1219 1220 'mov', 1220 1221 'avi', -
src/wp-admin/options-privacy.php
diff --git src/wp-admin/options-privacy.php src/wp-admin/options-privacy.php index a183abdf3f..3e4902daf4 100644
if ( ! current_user_can( 'manage_privacy_options' ) ) { 14 14 } 15 15 16 16 if ( isset( $_GET['tab'] ) && 'policyguide' === $_GET['tab'] ) { 17 require_once ( dirname( __FILE__ ) . '/privacy-policy-guide.php' );17 require_once dirname( __FILE__ ) . '/privacy-policy-guide.php'; 18 18 return; 19 19 } 20 20 -
src/wp-includes/ID3/getid3.lib.php
diff --git src/wp-includes/ID3/getid3.lib.php src/wp-includes/ID3/getid3.lib.php index 3a5983fc26..164cb31784 100644
class getid3_lib 1511 1511 if (is_writable($tempfilename) && is_file($tempfilename) && ($tmp = fopen($tempfilename, 'wb'))) { 1512 1512 fwrite($tmp, $imgData); 1513 1513 fclose($tmp); 1514 $GetDataImageSize = @getimagesize($tempfilename, $imageinfo);1514 $GetDataImageSize = wp_get_image_size($tempfilename, $imageinfo); 1515 1515 if (($GetDataImageSize === false) || !isset($GetDataImageSize[0]) || !isset($GetDataImageSize[1])) { 1516 1516 return false; 1517 1517 } -
src/wp-includes/ID3/getid3.php
diff --git src/wp-includes/ID3/getid3.php src/wp-includes/ID3/getid3.php index 5cb3c036c0..fbc05ba3f7 100644
class getID3 1183 1183 'fail_id3' => 'ERROR', 1184 1184 'fail_ape' => 'ERROR', 1185 1185 ), 1186 1186 'jpg' => array( 1187 'pattern' => '^WEBP', 1188 'group' => 'graphic', 1189 'module' => 'webp', 1190 'mime_type' => 'image/webp', 1191 'fail_id3' => 'ERROR', 1192 'fail_ape' => 'ERROR', 1193 ), 1187 1194 // PCD - still image - Kodak Photo CD 1188 1195 'pcd' => array( 1189 1196 'pattern' => '^.{2048}PCD_IPI\\x00', -
src/wp-includes/class-wp-image-editor-gd.php
diff --git src/wp-includes/class-wp-image-editor-gd.php src/wp-includes/class-wp-image-editor-gd.php index ed0a7be279..9fca3a692a 100644
class WP_Image_Editor_GD extends WP_Image_Editor { 69 69 return ( $image_types & IMG_PNG ) != 0; 70 70 case 'image/gif': 71 71 return ( $image_types & IMG_GIF ) != 0; 72 case 'image/webp': 73 return ( $image_types & IMG_WEBP ) != 0; 72 74 } 73 75 74 76 return false; … … class WP_Image_Editor_GD extends WP_Image_Editor { 99 101 return new WP_Error( 'error_loading_image', __( 'File doesn’t exist?' ), $this->file ); 100 102 } 101 103 102 $this->image = @imagecreatefromstring( $file_contents ); 104 // WebP may not work with imagecreatefromstring(). 105 if ( 106 function_exists( 'imagecreatefromwebp' ) && 107 ( 'image/webp' === wp_get_image_mime( $this->file ) ) 108 ) { 109 $this->image = @imagecreatefromwebp( $this->file ); 110 } else { 111 $this->image = @imagecreatefromstring( $file_contents ); 112 } 103 113 104 114 if ( ! is_gd_image( $this->image ) ) { 105 115 return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file ); 106 116 } 107 117 108 $size = wp_get imagesize( $this->file );118 $size = wp_get_image_size( $this->file ); 109 119 110 120 if ( ! $size ) { 111 121 return new WP_Error( 'invalid_image', __( 'Could not read image size.' ), $this->file ); … … class WP_Image_Editor_GD extends WP_Image_Editor { 459 469 if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) { 460 470 return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) ); 461 471 } 472 } elseif ( 'image/webp' == $mime_type ) { 473 if ( ! $this->make_image( $filename, 'imagewebp', array( $image, $filename, $this->get_quality() ) ) ) { 474 return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) ); 475 } 462 476 } else { 463 477 return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) ); 464 478 } … … class WP_Image_Editor_GD extends WP_Image_Editor { 502 516 case 'image/gif': 503 517 header( 'Content-Type: image/gif' ); 504 518 return imagegif( $this->image ); 519 case 'image/webp': 520 if ( function_exists( 'imagewebp' ) ) { 521 header( 'Content-Type: image/webp' ); 522 return imagewebp( $this->image, null, $this->get_quality() ); 523 } 524 // Fall back to the default if webp isn't supported. 505 525 default: 506 526 header( 'Content-Type: image/jpeg' ); 507 527 return imagejpeg( $this->image, null, $this->get_quality() ); -
src/wp-includes/class-wp-image-editor-imagick.php
diff --git src/wp-includes/class-wp-image-editor-imagick.php src/wp-includes/class-wp-image-editor-imagick.php index e4f1ea1b16..8744780330 100644
class WP_Image_Editor_Imagick extends WP_Image_Editor { 380 380 $this->image->setOption( 'png:exclude-chunk', 'all' ); 381 381 } 382 382 383 if ( 'image/webp' === $this->mime_type ) { 384 $this->image->setOption( 'webp:emulate-jpeg-size', true ); 385 } 386 383 387 /* 384 388 * If alpha channel is not defined, set it opaque. 385 389 * -
src/wp-includes/class-wp-theme.php
diff --git src/wp-includes/class-wp-theme.php src/wp-includes/class-wp-theme.php index 338df4b8f4..7d2c4294b7 100644
final class WP_Theme implements ArrayAccess { 1141 1141 return false; 1142 1142 } 1143 1143 1144 foreach ( array( 'png', 'gif', 'jpg', 'jpeg' ) as $ext ) {1144 foreach ( array( 'png', 'gif', 'jpg', 'jpeg', 'webp' ) as $ext ) { 1145 1145 if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) { 1146 1146 $this->cache_add( 'screenshot', 'screenshot.' . $ext ); 1147 1147 if ( 'relative' === $uri ) { -
src/wp-includes/compat.php
diff --git src/wp-includes/compat.php src/wp-includes/compat.php index 7f6c59f03c..c68c215bd3 100644
if ( ! function_exists( 'is_iterable' ) ) { 370 370 return ( is_array( $var ) || $var instanceof Traversable ); 371 371 } 372 372 } 373 374 // WebP constants may not be defined, even in cases where the format is supported. 375 if ( ! defined( 'IMAGETYPE_WEBP' ) ) { 376 define( 'IMAGETYPE_WEBP', 18 ); 377 } 378 if ( ! defined( 'IMG_WEBP' ) ) { 379 define( 'IMG_WEBP', IMAGETYPE_WEBP ); 380 } -
src/wp-includes/customize/class-wp-customize-media-control.php
diff --git src/wp-includes/customize/class-wp-customize-media-control.php src/wp-includes/customize/class-wp-customize-media-control.php index fc4801a96e..1dc1b8c277 100644
class WP_Customize_Media_Control extends WP_Customize_Control { 91 91 // Fake an attachment model - needs all fields used by template. 92 92 // Note that the default value must be a URL, NOT an attachment ID. 93 93 $ext = substr( $this->setting->default, -3 ); 94 $type = in_array( $ext, array( 'jpg', 'png', 'gif', 'bmp' ), true ) ? 'image' : 'document';94 $type = in_array( $ext, array( 'jpg', 'png', 'gif', 'bmp', 'webp' ), true ) ? 'image' : 'document'; 95 95 96 96 $default_attachment = array( 97 97 'id' => 1, -
src/wp-includes/deprecated.php
diff --git src/wp-includes/deprecated.php src/wp-includes/deprecated.php index 72a23cd836..4379fadda5 100644
function gd_edit_image_support($mime_type) { 3340 3340 return (imagetypes() & IMG_PNG) != 0; 3341 3341 case 'image/gif': 3342 3342 return (imagetypes() & IMG_GIF) != 0; 3343 case 'image/webp': 3344 return (imagetypes() & IMG_WEBP) != 0; 3343 3345 } 3344 3346 } else { 3345 3347 switch( $mime_type ) { … … function gd_edit_image_support($mime_type) { 3349 3351 return function_exists('imagecreatefrompng'); 3350 3352 case 'image/gif': 3351 3353 return function_exists('imagecreatefromgif'); 3354 case 'image/webp': 3355 return function_exists('imagecreatefromwebp'); 3352 3356 } 3353 3357 } 3354 3358 return false; -
src/wp-includes/formatting.php
diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php index b716c6bc1f..8dda8c738d 100644
function translate_smiley( $matches ) { 3318 3318 3319 3319 $matches = array(); 3320 3320 $ext = preg_match( '/\.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false; 3321 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );3321 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ); 3322 3322 3323 3323 // Don't convert smilies that aren't images - they're probably emoji. 3324 3324 if ( ! in_array( $ext, $image_exts, true ) ) { -
src/wp-includes/functions.php
diff --git src/wp-includes/functions.php src/wp-includes/functions.php index 56f50ce2de..4e9557286a 100644
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { 2880 2880 'image/gif' => 'gif', 2881 2881 'image/bmp' => 'bmp', 2882 2882 'image/tiff' => 'tif', 2883 'image/webp' => 'webp', 2883 2884 ) 2884 2885 ); 2885 2886 … … function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { 3031 3032 return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes, $real_mime ); 3032 3033 } 3033 3034 3035 /** 3036 * Wrapper for getimagesize() 3037 * 3038 * The native PHP function might not support newer formats. 3039 * 3040 * @since 5.0 3041 * 3042 * @see {https://core.trac.wordpress.org/ticket/35725} 3043 * 3044 * @param string $file Full path to the file. 3045 * @param array $info Additional metadata to pull. 3046 * @return array|false An array containing width, height, type constant, attributes, and media type. 3047 */ 3048 function wp_get_image_size( $file, &$info = array() ) { 3049 // Try getimagesize() first. 3050 $info = @getimagesize( $file, $info ); 3051 if ( false !== $info ) { 3052 return $info; 3053 } 3054 3055 // Support for WebP did not land in getimagesize() until PHP 7.1. But that's OK, 3056 // we can pull what we need from the file headers. 3057 if ( 'image/webp' === wp_get_image_mime( $file ) ) { 3058 try { 3059 $handle = fopen( $file, 'rb' ); 3060 if ( $handle ) { 3061 $magic = fread( $handle, 40 ); 3062 fclose( $handle ); 3063 3064 // Make sure we got enough bytes. 3065 if ( strlen( $magic ) < 40 ) { 3066 return false; 3067 } 3068 3069 $width = false; 3070 $height = false; 3071 3072 // The headers are a little different for each of the three formats. 3073 switch ( substr( $magic, 12, 4 ) ) { 3074 // Lossy WebP. 3075 case 'VP8 ': 3076 $parts = unpack( 'v2', substr( $magic, 26, 4 ) ); 3077 $width = (int) ( $parts[1] & 0x3FFF ); 3078 $height = (int) ( $parts[2] & 0x3FFF ); 3079 break; 3080 // Lossless WebP. 3081 case 'VP8L': 3082 $parts = unpack( 'C4', substr( $magic, 21, 4 ) ); 3083 $width = (int) ( $parts[1] | ( ( $parts[2] & 0x3F ) << 8 ) ) + 1; 3084 $height = (int) ( ( ( $parts[2] & 0xC0 ) >> 6 ) | 3085 ( $parts[3] << 2 ) | ( ( $parts[4] & 0x03 ) << 10 ) ) + 1; 3086 break; 3087 // Animated/alpha WebP. 3088 case 'VP8X': 3089 // Pad 24-bit int. 3090 $width = unpack( 'V', substr( $magic, 24, 3 ) . "\x00" ); 3091 $width = (int) ( $width[1] & 0xFFFFFF ) + 1; 3092 3093 // Pad 24-bit int. 3094 $height = unpack( 'V', substr( $magic, 27, 3 ) . "\x00" ); 3095 $height = (int) ( $height[1] & 0xFFFFFF ) + 1; 3096 break; 3097 } 3098 3099 // Mimic the native return format. 3100 if ( $width && $height ) { 3101 return array( 3102 $width, 3103 $height, 3104 IMAGETYPE_WEBP, 3105 sprintf( 3106 'width="%d" height="%d"', 3107 $width, 3108 $height 3109 ), 3110 'mime' => 'image/webp', 3111 ); 3112 } 3113 3114 // The image could not be parsed. 3115 return false; 3116 } 3117 } catch ( Exception $e ) { 3118 return false; 3119 } 3120 3121 return false; 3122 } 3123 } 3124 3034 3125 /** 3035 3126 * Returns the real mime type of an image file. 3036 3127 * … … function wp_get_image_mime( $file ) { 3052 3143 $imagetype = exif_imagetype( $file ); 3053 3144 $mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false; 3054 3145 } elseif ( function_exists( 'getimagesize' ) ) { 3055 $imagesize = wp_get imagesize( $file );3146 $imagesize = wp_get_image_size( $file ); 3056 3147 $mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false; 3057 3148 } else { 3058 3149 $mime = false; 3059 3150 } 3151 3152 // WebP support took longer to land in Exif than GD. 3153 if ( ! $mime ) { 3154 $handle = fopen( $file, 'rb' ); 3155 if ( $handle ) { 3156 $magic = bin2hex( fread( $handle, 12 ) ); 3157 if ( 3158 // RIFF. 3159 ( 0 === strpos( $magic, '52494646' ) ) && 3160 // WEBP. 3161 ( 16 === strpos( $magic, '57454250' ) ) 3162 ) { 3163 $mime = 'image/webp'; 3164 } 3165 fclose( $handle ); 3166 } 3167 } 3060 3168 } catch ( Exception $e ) { 3061 3169 $mime = false; 3062 3170 } … … function wp_get_ext_types() { 3216 3324 return apply_filters( 3217 3325 'ext2type', 3218 3326 array( 3219 'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic' ),3327 'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp' ), 3220 3328 'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), 3221 3329 'video' => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), 3222 3330 'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf' ), -
src/wp-includes/media.php
diff --git src/wp-includes/media.php src/wp-includes/media.php index 349bcbae1d..a9c725250c 100644
function image_downsize( $id, $size = 'medium' ) { 244 244 $info = null; 245 245 246 246 if ( $thumb_file ) { 247 $info = wp_get imagesize( $thumb_file );247 $info = wp_get_image_size( $thumb_file ); 248 248 } 249 249 250 250 if ( $thumb_file && $info ) { … … function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon 962 962 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); 963 963 964 964 $src_file = $icon_dir . '/' . wp_basename( $src ); 965 list( $width, $height ) = wp_get imagesize( $src_file );965 list( $width, $height ) = wp_get_image_size( $src_file ); 966 966 } 967 967 } 968 968 -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index b46d97bf14..42359e5f2c 100644
function wp_attachment_is( $type, $post = null ) { 6497 6497 6498 6498 switch ( $type ) { 6499 6499 case 'image': 6500 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );6500 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ); 6501 6501 return in_array( $ext, $image_exts, true ); 6502 6502 6503 6503 case 'audio': -
tests/phpunit/tests/functions.php
diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php index f485d3b4ec..980486b022 100644
class Tests_Functions extends WP_UnitTestCase { 1225 1225 $this->assertSame( $expected, wp_get_image_mime( $file ) ); 1226 1226 } 1227 1227 1228 /** 1229 * @ticket 35725 1230 * @dataProvider _wp_get_image_size 1231 */ 1232 public function test_wp_get_image_size( $file, $expected ) { 1233 if ( ! is_callable( 'exif_imagetype' ) && ! function_exists( 'getimagesize' ) ) { 1234 $this->markTestSkipped( 'The exif PHP extension is not loaded.' ); 1235 } 1236 1237 $result = wp_get_image_size( $file ); 1238 1239 // The getimagesize() function varies in its response, so 1240 // let's restrict comparison to expected keys only. 1241 if ( is_array( $expected ) ) { 1242 foreach ( $expected as $k => $v ) { 1243 $this->assertEquals( true, isset( $result[ $k ] ) ); 1244 $this->assertEquals( $expected[ $k ], $result[ $k ] ); 1245 } 1246 } else { 1247 $this->assertEquals( $expected, $result ); 1248 } 1249 } 1250 1228 1251 /** 1229 1252 * @ticket 39550 1230 1253 * @dataProvider _wp_check_filetype_and_ext_data … … class Tests_Functions extends WP_UnitTestCase { 1313 1336 DIR_TESTDATA . '/images/test-image-mime-jpg.png', 1314 1337 'image/jpeg', 1315 1338 ), 1339 // Animated WebP. 1340 array( 1341 DIR_TESTDATA . '/images/webp-animated.webp', 1342 'image/webp', 1343 ), 1344 // Lossless WebP. 1345 array( 1346 DIR_TESTDATA . '/images/webp-lossless.webp', 1347 'image/webp', 1348 ), 1349 // Lossy WebP. 1350 array( 1351 DIR_TESTDATA . '/images/webp-lossy.webp', 1352 'image/webp', 1353 ), 1354 // Transparent WebP. 1355 array( 1356 DIR_TESTDATA . '/images/webp-transparent.webp', 1357 'image/webp', 1358 ), 1359 // Not an image. 1360 array( 1361 DIR_TESTDATA . '/uploads/dashicons.woff', 1362 false, 1363 ), 1364 ); 1365 1366 return $data; 1367 } 1368 1369 /** 1370 * Data profider for test_wp_get_image_size(); 1371 */ 1372 public function _wp_get_image_size() { 1373 $data = array( 1374 // Standard JPEG. 1375 array( 1376 DIR_TESTDATA . '/images/test-image.jpg', 1377 array( 1378 50, 1379 50, 1380 IMAGETYPE_JPEG, 1381 'width="50" height="50"', 1382 'mime' => 'image/jpeg', 1383 ), 1384 ), 1385 // Standard GIF. 1386 array( 1387 DIR_TESTDATA . '/images/test-image.gif', 1388 array( 1389 50, 1390 50, 1391 IMAGETYPE_GIF, 1392 'width="50" height="50"', 1393 'mime' => 'image/gif', 1394 ), 1395 ), 1396 // Standard PNG. 1397 array( 1398 DIR_TESTDATA . '/images/test-image.png', 1399 array( 1400 50, 1401 50, 1402 IMAGETYPE_PNG, 1403 'width="50" height="50"', 1404 'mime' => 'image/png', 1405 ), 1406 ), 1407 // Image with wrong extension. 1408 array( 1409 DIR_TESTDATA . '/images/test-image-mime-jpg.png', 1410 array( 1411 50, 1412 50, 1413 IMAGETYPE_JPEG, 1414 'width="50" height="50"', 1415 'mime' => 'image/jpeg', 1416 ), 1417 ), 1418 // Animated WebP. 1419 array( 1420 DIR_TESTDATA . '/images/webp-animated.webp', 1421 array( 1422 100, 1423 100, 1424 IMAGETYPE_WEBP, 1425 'width="100" height="100"', 1426 'mime' => 'image/webp', 1427 ), 1428 ), 1429 // Lossless WebP. 1430 array( 1431 DIR_TESTDATA . '/images/webp-lossless.webp', 1432 array( 1433 1200, 1434 675, 1435 IMAGETYPE_WEBP, 1436 'width="1200" height="675"', 1437 'mime' => 'image/webp', 1438 ), 1439 ), 1440 // Lossy WebP. 1441 array( 1442 DIR_TESTDATA . '/images/webp-lossy.webp', 1443 array( 1444 1200, 1445 675, 1446 IMAGETYPE_WEBP, 1447 'width="1200" height="675"', 1448 'mime' => 'image/webp', 1449 ), 1450 ), 1451 // Transparent WebP. 1452 array( 1453 DIR_TESTDATA . '/images/webp-transparent.webp', 1454 array( 1455 1200, 1456 675, 1457 IMAGETYPE_WEBP, 1458 'width="1200" height="675"', 1459 'mime' => 'image/webp', 1460 ), 1461 ), 1316 1462 // Not an image. 1317 1463 array( 1318 1464 DIR_TESTDATA . '/uploads/dashicons.woff', -
tests/phpunit/tests/image/functions.php
diff --git tests/phpunit/tests/image/functions.php tests/phpunit/tests/image/functions.php index 1694c1e7f1..f2fb854f28 100644
class Tests_Image_Functions extends WP_UnitTestCase { 59 59 'test-image.psd', 60 60 'test-image-zip.tiff', 61 61 'test-image.jpg', 62 'webp-animated.webp', 63 'webp-lossless.webp', 64 'webp-lossy.webp', 65 'webp-transparent.webp', 62 66 ); 63 67 64 68 // IMAGETYPE_ICO is only defined in PHP 5.3+. … … class Tests_Image_Functions extends WP_UnitTestCase { 90 94 'test-image.gif', 91 95 'test-image.png', 92 96 'test-image.jpg', 97 'webp-animated.webp', 98 'webp-lossless.webp', 99 'webp-lossy.webp', 100 'webp-transparent.webp', 93 101 ); 94 102 95 103 // IMAGETYPE_ICO is only defined in PHP 5.3+. … … class Tests_Image_Functions extends WP_UnitTestCase { 172 180 'image/jpeg', 173 181 'image/gif', 174 182 'image/png', 183 'image/webp', 175 184 ); 176 185 177 186 // Test each image editor engine. … … class Tests_Image_Functions extends WP_UnitTestCase { 270 279 'jpe' => 'image/jpeg', 271 280 'gif' => 'image/gif', 272 281 'png' => 'image/png', 273 'unk' => 'image/jpeg', // Default, unknown. 282 'webp' => 'image/webp', 283 'unk' => 'image/jpeg', // Default, unknown. 274 284 ); 275 285 276 286 // Test each image editor engine.