Changeset 47122 for trunk/src/wp-includes/media.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r47060 r47122 74 74 $max_width = intval( get_option( 'thumbnail_size_w' ) ); 75 75 $max_height = intval( get_option( 'thumbnail_size_h' ) ); 76 // last chance thumbnail size defaults76 // Last chance thumbnail size defaults. 77 77 if ( ! $max_width && ! $max_height ) { 78 78 $max_width = 128; … … 110 110 $max_width = min( intval( $content_width ), $max_width ); 111 111 } 112 } else { // $size == 'full' has no constraint112 } else { // $size === 'full' has no constraint. 113 113 $max_width = $width; 114 114 $max_height = $height; … … 231 231 } 232 232 233 // try for a new style intermediate size233 // Try for a new style intermediate size. 234 234 $intermediate = image_get_intermediate_size( $id, $size ); 235 235 … … 240 240 $is_intermediate = true; 241 241 } elseif ( $size === 'thumbnail' ) { 242 // fall back to the old thumbnail242 // Fall back to the old thumbnail. 243 243 $thumb_file = wp_get_attachment_thumb_file( $id ); 244 244 $info = null; … … 257 257 258 258 if ( ! $width && ! $height && isset( $meta['width'], $meta['height'] ) ) { 259 // any other type: use the real image259 // Any other type: use the real image. 260 260 $width = $meta['width']; 261 261 $height = $meta['height']; … … 263 263 264 264 if ( $img_url ) { 265 // we have the actual image size, but might need to further constrain it if content_width is narrower265 // We have the actual image size, but might need to further constrain it if content_width is narrower. 266 266 list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size ); 267 267 … … 451 451 } 452 452 453 // Calculate the larger/smaller ratios 453 // Calculate the larger/smaller ratios. 454 454 $smaller_ratio = min( $width_ratio, $height_ratio ); 455 455 $larger_ratio = max( $width_ratio, $height_ratio ); … … 467 467 $h = max( 1, (int) round( $current_height * $ratio ) ); 468 468 469 // Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short 470 // We also have issues with recursive calls resulting in an ever-changing result. Constraining to the result of a constraint should yield the original result. 471 // Thus we look for dimensions that are one pixel shy of the max value and bump them up 469 /* 470 * Sometimes, due to rounding, we'll end up with a result like this: 471 * 465x700 in a 177x177 box is 117x176... a pixel short. 472 * We also have issues with recursive calls resulting in an ever-changing result. 473 * Constraining to the result of a constraint should yield the original result. 474 * Thus we look for dimensions that are one pixel shy of the max value and bump them up. 475 */ 472 476 473 477 // Note: $did_width means it is possible $smaller_ratio == $width_ratio. 474 478 if ( $did_width && $w === $max_width - 1 ) { 475 $w = $max_width; // Round it up 479 $w = $max_width; // Round it up. 476 480 } 477 481 478 482 // Note: $did_height means it is possible $smaller_ratio == $height_ratio. 479 483 if ( $did_height && $h === $max_height - 1 ) { 480 $h = $max_height; // Round it up 484 $h = $max_height; // Round it up. 481 485 } 482 486 … … 529 533 return false; 530 534 } 531 // at least one of dest_w or dest_h must be specific535 // At least one of $dest_w or $dest_h must be specific. 532 536 if ( $dest_w <= 0 && $dest_h <= 0 ) { 533 537 return false; … … 572 576 573 577 if ( $crop ) { 574 // Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h. 575 // Note that the requested crop dimensions are used as a maximum bounding box for the original image. 576 // If the original image's width or height is less than the requested width or height 577 // only the greater one will be cropped. 578 // For example when the original image is 600x300, and the requested crop dimensions are 400x400, 579 // the resulting image will be 400x300. 578 /* 579 * Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h. 580 * Note that the requested crop dimensions are used as a maximum bounding box for the original image. 581 * If the original image's width or height is less than the requested width or height 582 * only the greater one will be cropped. 583 * For example when the original image is 600x300, and the requested crop dimensions are 400x400, 584 * the resulting image will be 400x300. 585 */ 580 586 $aspect_ratio = $orig_w / $orig_h; 581 587 $new_w = min( $dest_w, $orig_w ); … … 822 828 } 823 829 824 // include the full filesystem path of the intermediate file830 // Include the full filesystem path of the intermediate file. 825 831 if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) { 826 832 $file_url = wp_get_attachment_url( $post_id ); … … 945 951 */ 946 952 function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) { 947 // get a thumbnail or intermediate image if there is one953 // Get a thumbnail or intermediate image if there is one. 948 954 $image = image_downsize( $attachment_id, $size ); 949 955 if ( ! $image ) { … … 1090 1096 1091 1097 if ( false !== strpos( $dirname, 'wp-content/uploads' ) ) { 1092 // Get the directory name relative to the upload directory (back compat for pre-2.7 uploads) 1098 // Get the directory name relative to the upload directory (back compat for pre-2.7 uploads). 1093 1099 $dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads' ) + 18 ); 1094 1100 $dirname = ltrim( $dirname, '/' ); … … 1741 1747 1742 1748 $html5 = current_theme_supports( 'html5', 'caption' ); 1743 // HTML5 captions never added the extra 10px to the image width 1749 // HTML5 captions never added the extra 10px to the image width. 1744 1750 $width = $html5 ? $atts['width'] : ( 10 + $atts['width'] ); 1745 1751 … … 2262 2268 } 2263 2269 2264 $outer = 22; // default padding and border of wrapper2270 $outer = 22; // Default padding and border of wrapper. 2265 2271 2266 2272 $default_width = 640; … … 2272 2278 $data = array( 2273 2279 'type' => $atts['type'], 2274 // don't pass strings to JSON, will be truthy in JS2280 // Don't pass strings to JSON, will be truthy in JS. 2275 2281 'tracklist' => wp_validate_boolean( $atts['tracklist'] ), 2276 2282 'tracknumbers' => wp_validate_boolean( $atts['tracknumbers'] ), … … 2602 2608 ); 2603 2609 2604 // These ones should just be omitted altogether if they are blank 2610 // These ones should just be omitted altogether if they are blank. 2605 2611 foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) { 2606 2612 if ( empty( $html_atts[ $a ] ) ) { … … 2755 2761 2756 2762 if ( is_admin() ) { 2757 // shrink the video so it isn't huge in the admin2763 // Shrink the video so it isn't huge in the admin. 2758 2764 if ( $atts['width'] > $defaults_atts['width'] ) { 2759 2765 $atts['height'] = round( ( $atts['height'] * $defaults_atts['width'] ) / $atts['width'] ); … … 2761 2767 } 2762 2768 } else { 2763 // if the video is bigger than the theme2769 // If the video is bigger than the theme. 2764 2770 if ( ! empty( $content_width ) && $atts['width'] > $content_width ) { 2765 2771 $atts['height'] = round( ( $atts['height'] * $content_width ) / $atts['width'] ); … … 2832 2838 } 2833 2839 2834 // Media element has issues with some URL formats for Vimeo and YouTube, so2835 // update the URL to prevent the ME.js player from breaking.2840 // MediaElement.js has issues with some URL formats for Vimeo and YouTube, 2841 // so update the URL to prevent the ME.js player from breaking. 2836 2842 if ( 'mediaelement' === $library ) { 2837 2843 if ( $is_youtube ) { … … 2872 2878 ); 2873 2879 2874 // These ones should just be omitted altogether if they are blank 2880 // These ones should just be omitted altogether if they are blank. 2875 2881 foreach ( array( 'poster', 'loop', 'autoplay', 'preload' ) as $a ) { 2876 2882 if ( empty( $html_atts[ $a ] ) ) { … … 3132 3138 * Create new GD image resource with transparency support 3133 3139 * 3134 * @todo :Deprecate if possible.3140 * @todo Deprecate if possible. 3135 3141 * 3136 3142 * @since 2.9.0 … … 3326 3332 */ 3327 3333 $defaults = array( 3328 'file_data_name' => 'async-upload', // key passed to $_FILE.3334 'file_data_name' => 'async-upload', // Key passed to $_FILE. 3329 3335 'url' => admin_url( 'async-upload.php', 'relative' ), 3330 3336 'filters' => array( … … 3334 3340 ); 3335 3341 3336 // Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos 3337 // when enabled. See #29602. 3342 /* 3343 * Currently only iOS Safari supports multiple files uploading, 3344 * but iOS 7.x has a bug that prevents uploading of videos when enabled. 3345 * See #29602. 3346 */ 3338 3347 if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false && 3339 3348 strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) { … … 3512 3521 unset( $possible_sizes['full'] ); 3513 3522 3514 // Loop through all potential sizes that may be chosen. Try to do this with some efficiency. 3515 // First: run the image_downsize filter. If it returns something, we can use its data. 3516 // If the filter does not return something, then image_downsize() is just an expensive 3517 // way to check the image metadata, which we do second. 3523 /* 3524 * Loop through all potential sizes that may be chosen. Try to do this with some efficiency. 3525 * First: run the image_downsize filter. If it returns something, we can use its data. 3526 * If the filter does not return something, then image_downsize() is just an expensive way 3527 * to check the image metadata, which we do second. 3528 */ 3518 3529 foreach ( $possible_sizes as $size => $label ) { 3519 3530 … … 3670 3681 3671 3682 $props = array( 3672 'link' => get_option( 'image_default_link_type' ), // db default is 'file'3673 'align' => get_option( 'image_default_align' ), // empty default3674 'size' => get_option( 'image_default_size' ), // empty default3683 'link' => get_option( 'image_default_link_type' ), // DB default is 'file'. 3684 'align' => get_option( 'image_default_align' ), // Empty default. 3685 'size' => get_option( 'image_default_size' ), // Empty default. 3675 3686 ); 3676 3687 … … 3841 3852 3842 3853 $strings = array( 3843 // Generic 3854 // Generic. 3844 3855 'mediaFrameDefaultTitle' => __( 'Media' ), 3845 3856 'url' => __( 'URL' ), … … 3860 3871 'dragInfo' => __( 'Drag and drop to reorder media files.' ), 3861 3872 3862 // Upload 3873 // Upload. 3863 3874 'uploadFilesTitle' => __( 'Upload Files' ), 3864 3875 'uploadImagesTitle' => __( 'Upload Images' ), 3865 3876 3866 // Library 3877 // Library. 3867 3878 'mediaLibraryTitle' => __( 'Media Library' ), 3868 3879 'insertMediaTitle' => __( 'Add Media' ), … … 3890 3901 'filterByType' => __( 'Filter by type' ), 3891 3902 'searchLabel' => __( 'Search' ), 3892 'searchMediaLabel' => __( 'Search Media' ), // backwards compatibility pre-5.33893 'searchMediaPlaceholder' => __( 'Search media items...' ), // placeholder (no ellipsis), backwards compatibility pre-5.33903 'searchMediaLabel' => __( 'Search Media' ), // Backward compatibility pre-5.3. 3904 'searchMediaPlaceholder' => __( 'Search media items...' ), // Placeholder (no ellipsis), backward compatibility pre-5.3. 3894 3905 'mediaFound' => __( 'Number of media items found: %d' ), 3895 3906 'mediaFoundHasMoreResults' => __( 'Number of media items displayed: %d. Scroll the page for more results.' ), … … 3897 3908 'noMediaTryNewSearch' => __( 'No media items found. Try a different search.' ), 3898 3909 3899 // Library Details 3910 // Library Details. 3900 3911 'attachmentDetails' => __( 'Attachment Details' ), 3901 3912 3902 // From URL 3913 // From URL. 3903 3914 'insertFromUrlTitle' => __( 'Insert from URL' ), 3904 3915 3905 // Featured Images 3916 // Featured Images. 3906 3917 'setFeaturedImageTitle' => $post_type_object->labels->featured_image, 3907 3918 'setFeaturedImage' => $post_type_object->labels->set_featured_image, 3908 3919 3909 // Gallery 3920 // Gallery. 3910 3921 'createGalleryTitle' => __( 'Create Gallery' ), 3911 3922 'editGalleryTitle' => __( 'Edit Gallery' ), … … 3917 3928 'reverseOrder' => __( 'Reverse order' ), 3918 3929 3919 // Edit Image 3930 // Edit Image. 3920 3931 'imageDetailsTitle' => __( 'Image Details' ), 3921 3932 'imageReplaceTitle' => __( 'Replace Image' ), … … 3923 3934 'editImage' => __( 'Edit Image' ), 3924 3935 3925 // Crop Image 3936 // Crop Image. 3926 3937 'chooseImage' => __( 'Choose Image' ), 3927 3938 'selectAndCrop' => __( 'Select and Crop' ), … … 3934 3945 'cropError' => __( 'There has been an error cropping your image.' ), 3935 3946 3936 // Edit Audio 3947 // Edit Audio. 3937 3948 'audioDetailsTitle' => __( 'Audio Details' ), 3938 3949 'audioReplaceTitle' => __( 'Replace Audio' ), … … 3940 3951 'audioDetailsCancel' => __( 'Cancel Edit' ), 3941 3952 3942 // Edit Video 3953 // Edit Video. 3943 3954 'videoDetailsTitle' => __( 'Video Details' ), 3944 3955 'videoReplaceTitle' => __( 'Replace Video' ), … … 3948 3959 'videoAddTrackTitle' => __( 'Add Subtitles' ), 3949 3960 3950 // Playlist 3961 // Playlist. 3951 3962 'playlistDragInfo' => __( 'Drag and drop to reorder tracks.' ), 3952 3963 'createPlaylistTitle' => __( 'Create Audio Playlist' ), … … 3958 3969 'addToPlaylistTitle' => __( 'Add to Audio Playlist' ), 3959 3970 3960 // Video Playlist 3971 // Video Playlist. 3961 3972 'videoPlaylistDragInfo' => __( 'Drag and drop to reorder videos.' ), 3962 3973 'createVideoPlaylistTitle' => __( 'Create Video Playlist' ), … … 3968 3979 'addToVideoPlaylistTitle' => __( 'Add to Video Playlist' ), 3969 3980 3970 // Headings 3981 // Headings. 3971 3982 'filterAttachments' => __( 'Filter Media' ), 3972 3983 'attachmentsList' => __( 'Media list' ), … … 3995 4006 $strings['settings'] = $settings; 3996 4007 3997 // Ensure we enqueue media-editor first, that way media-views is3998 // registered internally before we try to localize it. see #24724.4008 // Ensure we enqueue media-editor first, that way media-views 4009 // is registered internally before we try to localize it. See #24724. 3999 4010 wp_enqueue_script( 'media-editor' ); 4000 4011 wp_localize_script( 'media-views', '_wpMediaViewsL10n', $strings ); … … 4286 4297 $image_path = parse_url( $path ); 4287 4298 4288 // force the protocols to match if needed4299 // Force the protocols to match if needed. 4289 4300 if ( isset( $image_path['scheme'] ) && ( $image_path['scheme'] !== $site_url['scheme'] ) ) { 4290 4301 $path = str_replace( $image_path['scheme'], $site_url['scheme'], $path ); … … 4437 4448 */ 4438 4449 function _wp_add_additional_image_sizes() { 4439 // 2x medium_large size 4450 // 2x medium_large size. 4440 4451 add_image_size( '1536x1536', 1536, 1536 ); 4441 // 2x large size 4452 // 2x large size. 4442 4453 add_image_size( '2048x2048', 2048, 2048 ); 4443 4454 }
Note: See TracChangeset
for help on using the changeset viewer.