Scale down the default size of an image.

This is so that the image is a better fit for the editor and theme.

The $size parameter accepts either an array or a string. The supported string values are ‘thumb’ or ‘thumbnail’ for the given thumbnail size or defaults at 128 width and 96 height in pixels. Also supported for the string value is ‘medium’ and ‘full’. The ‘full’ isn’t actually supported, but any value other than the supported will result in the content_width size or 500 if that is not set.

Finally, there is a filter named ‘editor_max_image_size’, that will be called on the calculated array for width and height, respectively. The second parameter will be the value that was in the $size parameter. The returned type for the hook is an array with the width as the first element and the height as the second element.

Signature

image_constrain_size_for_editor( $width, $height, $size = 'medium', $context = null )
width
 (int) Width of the image
height
 (int) Height of the image
size
 (string|array) Size of what the result image should be.
Default: 'medium'
context
 (null)
Default: null

Return

(array) Width and height of what the result image should resize to.

Source

function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null ) {
	global $content_width, $_wp_additional_image_sizes;

	if ( ! $context )
		$context = is_admin() ? 'edit' : 'display';

	if ( is_array($size) ) {
		$max_width = $size[0];
		$max_height = $size[1];
	}
	elseif ( $size == 'thumb' || $size == 'thumbnail' ) {
		$max_width = intval(get_option('thumbnail_size_w'));
		$max_height = intval(get_option('thumbnail_size_h'));
		// last chance thumbnail size defaults
		if ( !$max_width && !$max_height ) {
			$max_width = 128;
			$max_height = 96;
		}
	}
	elseif ( $size == 'medium' ) {
41 more lines...
WP Trac GitHub

Link here