Media: Add two new intermediate image sizes, 1536px and 2048px. They are meant to enhance the way WordPress displays images on the front-end on larger, high-density devices. They make it possible to generate more suitable `srcset` and `sizes` attributes, and not use the original, often non-optimized image.

Also change the default `max_srcset_image_width` value to match the new max size.

Props pierlo, azaozz.
See #43524.

git-svn-id: https://develop.svn.wordpress.org/trunk@46066 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2019-09-05 22:26:50 +00:00
parent a211ce8f99
commit a38ecee8c9
2 changed files with 23 additions and 2 deletions

View File

@ -519,6 +519,7 @@ add_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop()
// Media
add_action( 'wp_playlist_scripts', 'wp_playlist_scripts' );
add_action( 'customize_controls_enqueue_scripts', 'wp_plupload_default_settings' );
add_action( 'plugins_loaded', '_wp_add_additional_image_sizes', 0 );
// Nav menu
add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 );

View File

@ -1200,10 +1200,10 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac
*
* @since 4.4.0
*
* @param int $max_width The maximum image width to be included in the 'srcset'. Default '1600'.
* @param int $max_width The maximum image width to be included in the 'srcset'. Default '2048'.
* @param array $size_array Array of width and height values in pixels (in that order).
*/
$max_srcset_image_width = apply_filters( 'max_srcset_image_width', 1600, $size_array );
$max_srcset_image_width = apply_filters( 'max_srcset_image_width', 2048, $size_array );
// Array to hold URL candidates.
$sources = array();
@ -4329,3 +4329,23 @@ function wp_media_personal_data_exporter( $email_address, $page = 1 ) {
'done' => $done,
);
}
/**
* Add additional default image sub-sizes.
*
* These sizes are meant to enhance the way WordPress displays images on the front-end on larger,
* high-density devices. They make it possible to generate more suitable `srcset` and `sizes` attributes
* when the users upload large images.
*
* The sizes can be changed or removed by themes and plugins but that is not recommended.
* The size "names" reflect the image dimensions, so changing the sizes would be quite misleading.
*
* @since 5.3.0
* @access private
*/
function _wp_add_additional_image_sizes() {
// 2x medium_large size
add_image_size( '1536x1536', 1536, 1536 );
// 2x large size
add_image_size( '2048x2048', 2048, 2048 );
}