Ticket #35725: 35725.10.diff
File 35725.10.diff, 29.4 KB (added by , 4 years ago) |
---|
-
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..261d8949fa 100644
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 file_is_valid_image( $path ) { 912 915 * @return bool True if suitable, false if not suitable. 913 916 */ 914 917 function file_is_displayable_image( $path ) { 915 $displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO );918 $displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_ICO, IMAGETYPE_WEBP ); // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound 916 919 917 920 $info = wp_getimagesize( $path ); 918 921 if ( empty( $info ) ) { … … 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 567cd1f823..4d3d2f3950 100644
function wp_media_upload_handler() { 993 993 function media_sideload_image( $file, $post_id = 0, $desc = null, $return = 'html' ) { 994 994 if ( ! empty( $file ) ) { 995 995 996 $allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif' );996 $allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'webp' ); 997 997 998 998 /** 999 999 * 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-includes/ID3/getid3.lib.php
diff --git src/wp-includes/ID3/getid3.lib.php src/wp-includes/ID3/getid3.lib.php index 3a5983fc26..3dfb653697 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_getimagesize($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..a5a9b50589 100644
class getID3 1183 1183 'fail_id3' => 'ERROR', 1184 1184 'fail_ape' => 'ERROR', 1185 1185 ), 1186 1186 'webp' => 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..964bc4c712 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; // phpcs:ignore PHPCompatibility.Constants.NewConstants.img_webpFound 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 ); … … 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.php
diff --git src/wp-includes/class-wp-image-editor.php src/wp-includes/class-wp-image-editor.php index 7dcdc91d5a..ad92a912f9 100644
abstract class WP_Image_Editor { 316 316 $new_ext = $file_ext; 317 317 } 318 318 319 // Remap legacy formats to modern formats. 320 $image_editor_mime_mapping = array( 321 // Map jpeg images to webp images by default. 322 'image/jpeg' => array( 323 'mime_type' => 'image/webp', 324 'extension' => 'webp', 325 ), 326 ); 327 328 /** 329 * Filters the default mime mapping. 330 * 331 * @see get_output_format() 332 * 333 * @since 5.8.0 334 * 335 * @param array $image_editor_mime_mapping { 336 * An array of mime type mappings. Maps a source mime type to a new 337 * destination mime type and file extension. 338 * 339 * @type array $mime_type The source mime type { 340 * @type string $mime_type The new mime type. 341 * @type string $extension The new mime file extension. 342 * } 343 * } 344 */ 345 $image_editor_mime_mapping = apply_filters( 'image_editor_mime_mapping', $image_editor_mime_mapping, $filename, $mime_type ); 346 347 if ( $image_editor_mime_mapping && isset( $image_editor_mime_mapping[ $mime_type ] ) && $image_editor_mime_mapping[ $mime_type ] ) { 348 $new_ext = $image_editor_mime_mapping[ $mime_type ]['extension']; 349 $mime_type = $image_editor_mime_mapping[ $mime_type ]['mime_type']; 350 } 351 319 352 // Double-check that the mime-type selected is supported by the editor. 320 353 // If not, choose a default instead. 321 354 if ( ! $this->supports_mime_type( $mime_type ) ) { -
src/wp-includes/class-wp-theme.php
diff --git src/wp-includes/class-wp-theme.php src/wp-includes/class-wp-theme.php index d9ccf6b6ba..b365f45715 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..59e5700439 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 ); // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound 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..2c5f24bde0 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; // phpcs:ignore PHPCompatibility.Constants.NewConstants.img_webpFound 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 56d5fd9f43..027ed3074c 100644
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { 2886 2886 'image/gif' => 'gif', 2887 2887 'image/bmp' => 'bmp', 2888 2888 'image/tiff' => 'tif', 2889 'image/webp' => 'webp', 2889 2890 ) 2890 2891 ); 2891 2892 … … function wp_get_image_mime( $file ) { 3063 3064 } else { 3064 3065 $mime = false; 3065 3066 } 3067 3068 // WebP support took longer to land in Exif than GD. 3069 if ( ! $mime ) { 3070 $handle = fopen( $file, 'rb' ); 3071 if ( $handle ) { 3072 $magic = bin2hex( fread( $handle, 12 ) ); 3073 if ( 3074 // RIFF. 3075 ( 0 === strpos( $magic, '52494646' ) ) && 3076 // WEBP. 3077 ( 16 === strpos( $magic, '57454250' ) ) 3078 ) { 3079 $mime = 'image/webp'; 3080 } 3081 fclose( $handle ); 3082 } 3083 } 3066 3084 } catch ( Exception $e ) { 3067 3085 $mime = false; 3068 3086 } … … function wp_get_mime_types() { 3101 3119 'png' => 'image/png', 3102 3120 'bmp' => 'image/bmp', 3103 3121 'tiff|tif' => 'image/tiff', 3122 'webp' => 'image/webp', 3104 3123 'ico' => 'image/x-icon', 3105 3124 'heic' => 'image/heic', 3106 3125 // Video formats. … … function wp_get_ext_types() { 3222 3241 return apply_filters( 3223 3242 'ext2type', 3224 3243 array( 3225 'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic' ),3244 'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp' ), 3226 3245 'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), 3227 3246 'video' => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), 3228 3247 '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 b0e2c79aef..e44eb589df 100644
function wp_show_heic_upload_error( $plupload_settings ) { 4974 4974 * Allows PHP's getimagesize() to be debuggable when necessary. 4975 4975 * 4976 4976 * @since 5.7.0 4977 * @since 5.8.0 Added support for WebP images. 4977 4978 * 4978 4979 * @param string $filename The file path. 4979 4980 * @param array $imageinfo Extended image information, passed by reference. … … function wp_getimagesize( $filename, &$imageinfo = array() ) { 4987 4988 // Return without silencing errors when in debug mode. 4988 4989 defined( 'WP_DEBUG' ) && WP_DEBUG 4989 4990 ) { 4990 return getimagesize( $filename, $imageinfo );4991 return _get_image_size( $filename, $imageinfo ); 4991 4992 } 4992 4993 4993 4994 /* … … function wp_getimagesize( $filename, &$imageinfo = array() ) { 5001 5002 * 5002 5003 * phpcs:ignore WordPress.PHP.NoSilencedErrors 5003 5004 */ 5004 return @getimagesize( $filename, $imageinfo ); 5005 return @_get_image_size( $filename, $imageinfo ); 5006 } 5007 5008 /** 5009 * Get the image size, with support for WebP images. 5010 * 5011 * @since 5.8.0 5012 * 5013 * @param string $filename The file path. 5014 * @param array $imageinfo Extended image information, passed by reference. 5015 */ 5016 function _get_image_size( $filename, &$imageinfo = array() ) { 5017 // Try getimagesize() first. 5018 $info = getimagesize( $filename, $imageinfo ); 5019 if ( false !== $info ) { 5020 return $info; 5021 } 5022 5023 // For PHP versions that don't support WebP images, pull info from the file headers. 5024 if ( 'image/webp' === wp_get_image_mime( $filename ) ) { 5025 try { 5026 $handle = fopen( $filename, 'rb' ); 5027 if ( $handle ) { 5028 $magic = fread( $handle, 40 ); 5029 fclose( $handle ); 5030 5031 // Make sure we got enough bytes. 5032 if ( strlen( $magic ) < 40 ) { 5033 return false; 5034 } 5035 5036 $width = false; 5037 $height = false; 5038 5039 // The headers are a little different for each of the three formats. 5040 switch ( substr( $magic, 12, 4 ) ) { 5041 // Lossy WebP. 5042 case 'VP8 ': 5043 $parts = unpack( 'v2', substr( $magic, 26, 4 ) ); 5044 $width = (int) ( $parts[1] & 0x3FFF ); 5045 $height = (int) ( $parts[2] & 0x3FFF ); 5046 break; 5047 // Lossless WebP. 5048 case 'VP8L': 5049 $parts = unpack( 'C4', substr( $magic, 21, 4 ) ); 5050 $width = (int) ( $parts[1] | ( ( $parts[2] & 0x3F ) << 8 ) ) + 1; 5051 $height = (int) ( ( ( $parts[2] & 0xC0 ) >> 6 ) | 5052 ( $parts[3] << 2 ) | ( ( $parts[4] & 0x03 ) << 10 ) ) + 1; 5053 break; 5054 // Animated/alpha WebP. 5055 case 'VP8X': 5056 // Pad 24-bit int. 5057 $width = unpack( 'V', substr( $magic, 24, 3 ) . "\x00" ); 5058 $width = (int) ( $width[1] & 0xFFFFFF ) + 1; 5059 5060 // Pad 24-bit int. 5061 $height = unpack( 'V', substr( $magic, 27, 3 ) . "\x00" ); 5062 $height = (int) ( $height[1] & 0xFFFFFF ) + 1; 5063 break; 5064 } 5065 5066 // Mimic the native return format. 5067 if ( $width && $height ) { 5068 return array( 5069 $width, 5070 $height, 5071 IMAGETYPE_WEBP, // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound 5072 sprintf( 5073 'width="%d" height="%d"', 5074 $width, 5075 $height 5076 ), 5077 'mime' => 'image/webp', 5078 ); 5079 } 5080 5081 // The image could not be parsed. 5082 return false; 5083 } 5084 } catch ( Exception $e ) { 5085 return false; 5086 } 5087 5088 return false; 5089 } 5005 5090 } -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index ced0275db4..6d1f03647d 100644
function wp_attachment_is( $type, $post = null ) { 6535 6535 6536 6536 switch ( $type ) { 6537 6537 case 'image': 6538 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );6538 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ); 6539 6539 return in_array( $ext, $image_exts, true ); 6540 6540 6541 6541 case 'audio': -
tests/phpunit/tests/functions.php
diff --git tests/phpunit/data/images/webp-animated.webp tests/phpunit/data/images/webp-animated.webp new file mode 100644 index 0000000000..c60d334a82 Binary files /dev/null and tests/phpunit/data/images/webp-animated.webp differ diff --git tests/phpunit/data/images/webp-lossless.webp tests/phpunit/data/images/webp-lossless.webp new file mode 100644 index 0000000000..7a3a06e0b4 Binary files /dev/null and tests/phpunit/data/images/webp-lossless.webp differ diff --git tests/phpunit/data/images/webp-lossy.webp tests/phpunit/data/images/webp-lossy.webp new file mode 100644 index 0000000000..c8b0e25391 Binary files /dev/null and tests/phpunit/data/images/webp-lossy.webp differ diff --git tests/phpunit/data/images/webp-transparent.webp tests/phpunit/data/images/webp-transparent.webp new file mode 100644 index 0000000000..c4b24a08be Binary files /dev/null and tests/phpunit/data/images/webp-transparent.webp differ diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php index f485d3b4ec..75a2ecf5e0 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_getimagesize 1231 */ 1232 public function test_wp_getimagesize( $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_getimagesize( $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_getimagesize(); 1371 */ 1372 public function _wp_getimagesize() { 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/editorGd.php
diff --git tests/phpunit/tests/image/editorGd.php tests/phpunit/tests/image/editorGd.php index d2523f4c6f..d2493d9650 100644
class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 17 17 require_once ABSPATH . WPINC . '/class-wp-image-editor.php'; 18 18 require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php'; 19 19 20 add_filter( 'image_editor_mime_mapping', '__return_false' ); 21 20 22 // This needs to come after the mock image editor class is loaded. 21 23 parent::setUp(); 22 24 } … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 29 31 } 30 32 31 33 $this->remove_added_uploads(); 34 remove_filter( 'image_editor_mime_mapping', '__return_false' ); 32 35 33 36 parent::tearDown(); 34 37 } … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 110 113 ); 111 114 } 112 115 116 /** 117 * Test multi_resize with single image resize and no crop, with auto conversion 118 * to the webp format. 119 */ 120 public function test_single_multi_resize_to_webp() { 121 remove_filter( 'image_editor_mime_mapping', '__return_false' ); 122 123 $file = DIR_TESTDATA . '/images/waffles.jpg'; 124 125 $gd_image_editor = new WP_Image_Editor_GD( $file ); 126 $gd_image_editor->load(); 127 128 $sizes_array = array( 129 array( 130 'width' => 50, 131 'height' => 50, 132 ), 133 ); 134 135 $resized = $gd_image_editor->multi_resize( $sizes_array ); 136 137 // First, check to see if returned array is as expected. 138 $expected_array = array( 139 array( 140 'file' => 'waffles-50x33.webp', 141 'width' => 50, 142 'height' => 33, 143 'mime-type' => 'image/webp', 144 ), 145 ); 146 147 $this->assertSame( $expected_array, $resized ); 148 149 // Now, verify real dimensions are as expected. 150 $image_path = DIR_TESTDATA . '/images/' . $resized[0]['file']; 151 $this->assertImageDimensions( 152 $image_path, 153 $expected_array[0]['width'], 154 $expected_array[0]['height'] 155 ); 156 add_filter( 'image_editor_mime_mapping', '__return_false' ); 157 } 158 159 113 160 /** 114 161 * Ensure multi_resize doesn't create an image when 115 162 * both height and weight are missing, null, or 0. -
tests/phpunit/tests/image/functions.php
diff --git tests/phpunit/tests/image/functions.php tests/phpunit/tests/image/functions.php index 1694c1e7f1..315e6aae90 100644
class Tests_Image_Functions extends WP_UnitTestCase { 25 25 foreach ( glob( $folder ) as $file ) { 26 26 unlink( $file ); 27 27 } 28 add_filter( 'image_editor_mime_mapping', '__return_false' ); 29 } 30 31 public function tearDown() { 32 parent::tearDown(); 33 remove_filter( 'image_editor_mime_mapping', '__return_false' ); 28 34 } 29 35 30 36 /** … … class Tests_Image_Functions extends WP_UnitTestCase { 59 65 'test-image.psd', 60 66 'test-image-zip.tiff', 61 67 'test-image.jpg', 68 'webp-animated.webp', 69 'webp-lossless.webp', 70 'webp-lossy.webp', 71 'webp-transparent.webp', 62 72 ); 63 73 64 74 // IMAGETYPE_ICO is only defined in PHP 5.3+. … … class Tests_Image_Functions extends WP_UnitTestCase { 90 100 'test-image.gif', 91 101 'test-image.png', 92 102 'test-image.jpg', 103 'webp-animated.webp', 104 'webp-lossless.webp', 105 'webp-lossy.webp', 106 'webp-transparent.webp', 93 107 ); 94 108 95 109 // IMAGETYPE_ICO is only defined in PHP 5.3+. … … class Tests_Image_Functions extends WP_UnitTestCase { 152 166 * @requires extension fileinfo 153 167 */ 154 168 public function test_wp_save_image_file() { 169 add_filter( 'image_editor_mime_mapping', '__return_false' ); 155 170 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); 156 171 157 172 foreach ( $classes as $key => $class ) { … … class Tests_Image_Functions extends WP_UnitTestCase { 172 187 'image/jpeg', 173 188 'image/gif', 174 189 'image/png', 190 'image/webp', 175 191 ); 176 192 177 193 // Test each image editor engine. … … class Tests_Image_Functions extends WP_UnitTestCase { 270 286 'jpe' => 'image/jpeg', 271 287 'gif' => 'image/gif', 272 288 'png' => 'image/png', 273 'unk' => 'image/jpeg', // Default, unknown. 289 'webp' => 'image/webp', 290 'unk' => 'image/jpeg', // Default, unknown. 274 291 ); 275 292 276 293 // Test each image editor engine. -
tests/phpunit/tests/image/intermediateSize.php
diff --git tests/phpunit/tests/image/intermediateSize.php tests/phpunit/tests/image/intermediateSize.php index b92c833a9d..08b3a015de 100644
5 5 * @group upload 6 6 */ 7 7 class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 8 /** 9 * Setup test fixture 10 */ 11 public function setUp() { 12 parent::setUp(); 13 add_filter( 'image_editor_mime_mapping', '__return_false' ); 14 } 15 8 16 function tearDown() { 9 17 $this->remove_added_uploads(); 10 18 … … class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 12 20 remove_image_size( 'false-height' ); 13 21 remove_image_size( 'false-width' ); 14 22 remove_image_size( 'off-by-one' ); 23 remove_filter( 'image_editor_mime_mapping', '__return_false' ); 15 24 parent::tearDown(); 16 25 } 17 26 -
tests/phpunit/tests/image/resize.php
diff --git tests/phpunit/tests/image/resize.php tests/phpunit/tests/image/resize.php index 3e3255e6a5..cc66256769 100644
abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase 14 14 parent::setUp(); 15 15 16 16 add_filter( 'wp_image_editors', array( $this, 'wp_image_editors' ) ); 17 add_filter( 'image_editor_mime_mapping', '__return_false' ); 18 } 19 20 public function tearDown() { 21 parent::tearDown(); 22 remove_filter( 'image_editor_mime_mapping', '__return_false' ); 17 23 } 18 24 19 25 public function wp_image_editors() { -
tests/phpunit/tests/media.php
diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php index bc9b593d15..df755691ba 100644
class Tests_Media extends WP_UnitTestCase { 11 11 protected static $post_ids; 12 12 13 13 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 14 add_filter( 'image_editor_mime_mapping', '__return_false' ); 15 14 16 self::$_sizes = wp_get_additional_image_sizes(); 15 17 $GLOBALS['_wp_additional_image_sizes'] = array(); 16 18 … … class Tests_Media extends WP_UnitTestCase { 49 51 50 52 public static function wpTearDownAfterClass() { 51 53 $GLOBALS['_wp_additional_image_sizes'] = self::$_sizes; 54 remove_filter( 'image_editor_mime_mapping', '__return_false' ); 52 55 } 53 56 54 57 public static function tearDownAfterClass() { -
tests/phpunit/tests/post/attachments.php
diff --git tests/phpunit/tests/post/attachments.php tests/phpunit/tests/post/attachments.php index 0a03d77ed6..ff3ba64541 100644
6 6 * @group upload 7 7 */ 8 8 class Tests_Post_Attachments extends WP_UnitTestCase { 9 /** 10 * Setup test fixture 11 */ 12 public function setUp() { 13 parent::setUp(); 14 add_filter( 'image_editor_mime_mapping', '__return_false' ); 15 } 9 16 10 17 function tearDown() { 11 18 // Remove all uploads. 12 19 $this->remove_added_uploads(); 20 remove_filter( 'image_editor_mime_mapping', '__return_false' ); 13 21 parent::tearDown(); 14 22 } 15 23