image_constrain_size_for_editor

The timeline below displays how wordpress function image_constrain_size_for_editor has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Scales 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', 'medium_large' 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 {@see 'editor_max_image_size'}, that will be
 * called on the calculated array for width and height, respectively.
 *
 * @since 2.5.0
 *
 * @global int $content_width
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|int[] $size    Optional. Image size. Accepts any registered image size name, or an array
 *                              of width and height values in pixels (in that order). Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return int[] {
 *     An array of width and height values.
 *
 *     @type int $0 The maximum width in pixels.
 *     @type int $1 The maximum height in pixels.
 * }
 */
function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null)
{
    global $content_width;
    $_wp_additional_image_sizes = wp_get_additional_image_sizes();
    if (!$context) {
        $context = is_admin() ? 'edit' : 'display';
    }
    if (is_array($size)) {
        $max_width = $size[0];
        $max_height = $size[1];
    } elseif ('thumb' === $size || 'thumbnail' === $size) {
        $max_width = (int) get_option('thumbnail_size_w');
        $max_height = (int) get_option('thumbnail_size_h');
        // Last chance thumbnail size defaults.
        if (!$max_width && !$max_height) {
            $max_width = 128;
            $max_height = 96;
        }
    } elseif ('medium' === $size) {
        $max_width = (int) get_option('medium_size_w');
        $max_height = (int) get_option('medium_size_h');
    } elseif ('medium_large' === $size) {
        $max_width = (int) get_option('medium_large_size_w');
        $max_height = (int) get_option('medium_large_size_h');
        if ((int) $content_width > 0) {
            $max_width = min((int) $content_width, $max_width);
        }
    } elseif ('large' === $size) {
        /*
         * We're inserting a large size image into the editor. If it's a really
         * big image we'll scale it down to fit reasonably within the editor
         * itself, and within the theme's content width if it's known. The user
         * can resize it in the editor if they wish.
         */
        $max_width = (int) get_option('large_size_w');
        $max_height = (int) get_option('large_size_h');
        if ((int) $content_width > 0) {
            $max_width = min((int) $content_width, $max_width);
        }
    } elseif (!empty($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes), true)) {
        $max_width = (int) $_wp_additional_image_sizes[$size]['width'];
        $max_height = (int) $_wp_additional_image_sizes[$size]['height'];
        // Only in admin. Assume that theme authors know what they're doing.
        if ((int) $content_width > 0 && 'edit' === $context) {
            $max_width = min((int) $content_width, $max_width);
        }
    } else {
        // $size === 'full' has no constraint.
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filters the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param int[]        $max_image_size {
     *     An array of width and height values.
     *
     *     @type int $0 The maximum width in pixels.
     *     @type int $1 The maximum height in pixels.
     * }
     * @param string|int[] $size     Requested image size. Can be any registered image size name, or
     *                               an array of width and height values in pixels (in that order).
     * @param string       $context  The context the image is being resized for.
     *                               Possible values are 'display' (like in a theme)
     *                               or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 5.6

/**
 * 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', 'medium_large' 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 {@see 'editor_max_image_size'}, that will be
 * called on the calculated array for width and height, respectively.
 *
 * @since 2.5.0
 *
 * @global int $content_width
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|int[] $size    Optional. Image size. Accepts any registered image size name, or an array
 *                              of width and height values in pixels (in that order). Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return int[] {
 *     An array of width and height values.
 *
 *     @type int $0 The maximum width in pixels.
 *     @type int $1 The maximum height in pixels.
 * }
 */
function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null)
{
    global $content_width;
    $_wp_additional_image_sizes = wp_get_additional_image_sizes();
    if (!$context) {
        $context = is_admin() ? 'edit' : 'display';
    }
    if (is_array($size)) {
        $max_width = $size[0];
        $max_height = $size[1];
    } elseif ('thumb' === $size || 'thumbnail' === $size) {
        $max_width = (int) get_option('thumbnail_size_w');
        $max_height = (int) get_option('thumbnail_size_h');
        // Last chance thumbnail size defaults.
        if (!$max_width && !$max_height) {
            $max_width = 128;
            $max_height = 96;
        }
    } elseif ('medium' === $size) {
        $max_width = (int) get_option('medium_size_w');
        $max_height = (int) get_option('medium_size_h');
    } elseif ('medium_large' === $size) {
        $max_width = (int) get_option('medium_large_size_w');
        $max_height = (int) get_option('medium_large_size_h');
        if ((int) $content_width > 0) {
            $max_width = min((int) $content_width, $max_width);
        }
    } elseif ('large' === $size) {
        /*
         * We're inserting a large size image into the editor. If it's a really
         * big image we'll scale it down to fit reasonably within the editor
         * itself, and within the theme's content width if it's known. The user
         * can resize it in the editor if they wish.
         */
        $max_width = (int) get_option('large_size_w');
        $max_height = (int) get_option('large_size_h');
        if ((int) $content_width > 0) {
            $max_width = min((int) $content_width, $max_width);
        }
    } elseif (!empty($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes), true)) {
        $max_width = (int) $_wp_additional_image_sizes[$size]['width'];
        $max_height = (int) $_wp_additional_image_sizes[$size]['height'];
        // Only in admin. Assume that theme authors know what they're doing.
        if ((int) $content_width > 0 && 'edit' === $context) {
            $max_width = min((int) $content_width, $max_width);
        }
    } else {
        // $size === 'full' has no constraint.
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filters the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param int[]        $max_image_size {
     *     An array of width and height values.
     *
     *     @type int $0 The maximum width in pixels.
     *     @type int $1 The maximum height in pixels.
     * }
     * @param string|int[] $size     Requested image size. Can be any registered image size name, or
     *                               an array of width and height values in pixels (in that order).
     * @param string       $context  The context the image is being resized for.
     *                               Possible values are 'display' (like in a theme)
     *                               or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 5.4

/**
 * 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', 'medium_large' 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 {@see 'editor_max_image_size'}, that will be
 * called on the calculated array for width and height, respectively.
 *
 * @since 2.5.0
 *
 * @global int   $content_width
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|array $size    Optional. Image size. Accepts any valid image size, or an array
 *                              of width and height values in pixels (in that order).
 *                              Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return int[] {
 *     An array of width and height values.
 *
 *     @type int $0 The maximum width in pixels.
 *     @type int $1 The maximum height in pixels.
 * }
 */
function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null)
{
    global $content_width;
    $_wp_additional_image_sizes = wp_get_additional_image_sizes();
    if (!$context) {
        $context = is_admin() ? 'edit' : 'display';
    }
    if (is_array($size)) {
        $max_width = $size[0];
        $max_height = $size[1];
    } elseif ('thumb' === $size || 'thumbnail' === $size) {
        $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 ('medium' === $size) {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
    } elseif ('medium_large' === $size) {
        $max_width = intval(get_option('medium_large_size_w'));
        $max_height = intval(get_option('medium_large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif ('large' === $size) {
        /*
         * We're inserting a large size image into the editor. If it's a really
         * big image we'll scale it down to fit reasonably within the editor
         * itself, and within the theme's content width if it's known. The user
         * can resize it in the editor if they wish.
         */
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (!empty($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes), true)) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        // Only in admin. Assume that theme authors know what they're doing.
        if (intval($content_width) > 0 && 'edit' === $context) {
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        // $size === 'full' has no constraint.
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filters the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param int[]        $max_image_size {
     *     An array of width and height values.
     *
     *     @type int $0 The maximum width in pixels.
     *     @type int $1 The maximum height in pixels.
     * }
     * @param string|array $size           Size of what the result image should be.
     * @param string       $context        The context the image is being resized for.
     *                                     Possible values are 'display' (like in a theme)
     *                                     or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 5.3

/**
 * 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', 'medium_large' 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 {@see '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.
 *
 * @since 2.5.0
 *
 * @global int   $content_width
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|array $size    Optional. Image size. Accepts any valid image size, or an array
 *                              of width and height values in pixels (in that order).
 *                              Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return array Width and height of what the result image should resize to.
 */
function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null)
{
    global $content_width;
    $_wp_additional_image_sizes = wp_get_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') {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
    } elseif ($size === 'medium_large') {
        $max_width = intval(get_option('medium_large_size_w'));
        $max_height = intval(get_option('medium_large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif ($size === 'large') {
        /*
         * We're inserting a large size image into the editor. If it's a really
         * big image we'll scale it down to fit reasonably within the editor
         * itself, and within the theme's content width if it's known. The user
         * can resize it in the editor if they wish.
         */
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (!empty($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes), true)) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        // Only in admin. Assume that theme authors know what they're doing.
        if (intval($content_width) > 0 && 'edit' === $context) {
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        // $size == 'full' has no constraint
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filters the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param array        $max_image_size An array with the width as the first element,
     *                                     and the height as the second element.
     * @param string|array $size           Size of what the result image should be.
     * @param string       $context        The context the image is being resized for.
     *                                     Possible values are 'display' (like in a theme)
     *                                     or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 5.1

/**
 * 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', 'medium_large' 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 {@see '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.
 *
 * @since 2.5.0
 *
 * @global int   $content_width
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|array $size    Optional. Image size. Accepts any valid image size, or an array
 *                              of width and height values in pixels (in that order).
 *                              Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return array Width and height of what the result image should resize to.
 */
function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null)
{
    global $content_width;
    $_wp_additional_image_sizes = wp_get_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') {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
    } elseif ($size == 'medium_large') {
        $max_width = intval(get_option('medium_large_size_w'));
        $max_height = intval(get_option('medium_large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif ($size == 'large') {
        /*
         * We're inserting a large size image into the editor. If it's a really
         * big image we'll scale it down to fit reasonably within the editor
         * itself, and within the theme's content width if it's known. The user
         * can resize it in the editor if they wish.
         */
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (!empty($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        // Only in admin. Assume that theme authors know what they're doing.
        if (intval($content_width) > 0 && 'edit' === $context) {
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        // $size == 'full' has no constraint
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filters the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param array        $max_image_size An array with the width as the first element,
     *                                     and the height as the second element.
     * @param string|array $size           Size of what the result image should be.
     * @param string       $context        The context the image is being resized for.
     *                                     Possible values are 'display' (like in a theme)
     *                                     or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 4.7

/**
 * 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', 'medium_large' 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 {@see '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.
 *
 * @since 2.5.0
 *
 * @global int   $content_width
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|array $size    Optional. Image size. Accepts any valid image size, or an array
 *                              of width and height values in pixels (in that order).
 *                              Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return array Width and height of what the result image should resize to.
 */
function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null)
{
    global $content_width;
    $_wp_additional_image_sizes = wp_get_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') {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
    } elseif ($size == 'medium_large') {
        $max_width = intval(get_option('medium_large_size_w'));
        $max_height = intval(get_option('medium_large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif ($size == 'large') {
        /*
         * We're inserting a large size image into the editor. If it's a really
         * big image we'll scale it down to fit reasonably within the editor
         * itself, and within the theme's content width if it's known. The user
         * can resize it in the editor if they wish.
         */
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (!empty($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        // Only in admin. Assume that theme authors know what they're doing.
        if (intval($content_width) > 0 && 'edit' === $context) {
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filters the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param array        $max_image_size An array with the width as the first element,
     *                                     and the height as the second element.
     * @param string|array $size           Size of what the result image should be.
     * @param string       $context        The context the image is being resized for.
     *                                     Possible values are 'display' (like in a theme)
     *                                     or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 4.6

/**
 * WordPress API for media display.
 *
 * @package WordPress
 * @subpackage Media
 */
/**
 * 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', 'medium_large' 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 {@see '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.
 *
 * @since 2.5.0
 *
 * @global int   $content_width
 * @global array $_wp_additional_image_sizes
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|array $size    Optional. Image size. Accepts any valid image size, or an array
 *                              of width and height values in pixels (in that order).
 *                              Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return array Width and height of what the result image should resize to.
 */
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') {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
    } elseif ($size == 'medium_large') {
        $max_width = intval(get_option('medium_large_size_w'));
        $max_height = intval(get_option('medium_large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif ($size == 'large') {
        /*
         * We're inserting a large size image into the editor. If it's a really
         * big image we'll scale it down to fit reasonably within the editor
         * itself, and within the theme's content width if it's known. The user
         * can resize it in the editor if they wish.
         */
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        if (intval($content_width) > 0 && 'edit' == $context) {
            // Only in admin. Assume that theme authors know what they're doing.
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filters the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param array        $max_image_size An array with the width as the first element,
     *                                     and the height as the second element.
     * @param string|array $size           Size of what the result image should be.
     * @param string       $context        The context the image is being resized for.
     *                                     Possible values are 'display' (like in a theme)
     *                                     or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 4.4

/**
 * WordPress API for media display.
 *
 * @package WordPress
 * @subpackage Media
 */
/**
 * 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', 'medium_large' 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 {@see '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.
 *
 * @since 2.5.0
 *
 * @global int   $content_width
 * @global array $_wp_additional_image_sizes
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|array $size    Optional. Image size. Accepts any valid image size, or an array
 *                              of width and height values in pixels (in that order).
 *                              Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return array Width and height of what the result image should resize to.
 */
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') {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
    } elseif ($size == 'medium_large') {
        $max_width = intval(get_option('medium_large_size_w'));
        $max_height = intval(get_option('medium_large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif ($size == 'large') {
        /*
         * We're inserting a large size image into the editor. If it's a really
         * big image we'll scale it down to fit reasonably within the editor
         * itself, and within the theme's content width if it's known. The user
         * can resize it in the editor if they wish.
         */
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        if (intval($content_width) > 0 && 'edit' == $context) {
            // Only in admin. Assume that theme authors know what they're doing.
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filter the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param array        $max_image_size An array with the width as the first element,
     *                                     and the height as the second element.
     * @param string|array $size           Size of what the result image should be.
     * @param string       $context        The context the image is being resized for.
     *                                     Possible values are 'display' (like in a theme)
     *                                     or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 4.3

/**
 * WordPress API for media display.
 *
 * @package WordPress
 * @subpackage Media
 */
/**
 * 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 {@see '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.
 *
 * @since 2.5.0
 *
 * @global int   $content_width
 * @global array $_wp_additional_image_sizes
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|array $size    Optional. Size or array of sizes of what the result image
 *                              should be. Accepts any valid image size name. Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return array Width and height of what the result image should resize to.
 */
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') {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
        // if no width is set, default to the theme content width if available
    } elseif ($size == 'large') {
        /*
         * We're inserting a large size image into the editor. If it's a really
         * big image we'll scale it down to fit reasonably within the editor
         * itself, and within the theme's content width if it's known. The user
         * can resize it in the editor if they wish.
         */
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        if (intval($content_width) > 0 && 'edit' == $context) {
            // Only in admin. Assume that theme authors know what they're doing.
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filter the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param array        $max_image_size An array with the width as the first element,
     *                                     and the height as the second element.
     * @param string|array $size           Size of what the result image should be.
     * @param string       $context        The context the image is being resized for.
     *                                     Possible values are 'display' (like in a theme)
     *                                     or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 4.2

/**
 * WordPress API for media display.
 *
 * @package WordPress
 * @subpackage Media
 */
/**
 * 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 {@see '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.
 *
 * @since 2.5.0
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|array $size    Optional. Size or array of sizes of what the result image
 *                              should be. Accepts any valid image size name. Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return array Width and height of what the result image should resize to.
 */
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') {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
        // if no width is set, default to the theme content width if available
    } elseif ($size == 'large') {
        /*
         * We're inserting a large size image into the editor. If it's a really
         * big image we'll scale it down to fit reasonably within the editor
         * itself, and within the theme's content width if it's known. The user
         * can resize it in the editor if they wish.
         */
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        if (intval($content_width) > 0 && 'edit' == $context) {
            // Only in admin. Assume that theme authors know what they're doing.
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filter the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param array        $max_image_size An array with the width as the first element,
     *                                     and the height as the second element.
     * @param string|array $size           Size of what the result image should be.
     * @param string       $context        The context the image is being resized for.
     *                                     Possible values are 'display' (like in a theme)
     *                                     or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 4.1

/**
 * WordPress API for media display.
 *
 * @package WordPress
 * @subpackage Media
 */
/**
 * 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 {@see '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.
 *
 * @since 2.5.0
 *
 * @param int          $width   Width of the image in pixels.
 * @param int          $height  Height of the image in pixels.
 * @param string|array $size    Optional. Size or array of sizes of what the result image
 *                              should be. Accepts any valid image size name. Default 'medium'.
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
 *                              (like inserting into an editor). Default null.
 * @return array Width and height of what the result image should resize to.
 */
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') {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
        // if no width is set, default to the theme content width if available
    } elseif ($size == 'large') {
        // We're inserting a large size image into the editor. If it's a really
        // big image we'll scale it down to fit reasonably within the editor
        // itself, and within the theme's content width if it's known. The user
        // can resize it in the editor if they wish.
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        if (intval($content_width) > 0 && 'edit' == $context) {
            // Only in admin. Assume that theme authors know what they're doing.
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filter the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param array        $max_image_size An array with the width as the first element,
     *                                     and the height as the second element.
     * @param string|array $size           Size of what the result image should be.
     * @param string       $context        The context the image is being resized for.
     *                                     Possible values are 'display' (like in a theme)
     *                                     or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 3.9

/**
 * WordPress API for media display.
 *
 * @package WordPress
 * @subpackage Media
 */
/**
 * 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.
 *
 * @since 2.5.0
 * @uses wp_constrain_dimensions() This function passes the widths and the heights.
 *
 * @param int $width Width of the image
 * @param int $height Height of the image
 * @param string|array $size Size of what the result image should be.
 * @param context Could be 'display' (like in a theme) or 'edit' (like inserting into an editor)
 * @return array Width and height of what the result image should resize to.
 */
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') {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
        // if no width is set, default to the theme content width if available
    } elseif ($size == 'large') {
        // We're inserting a large size image into the editor. If it's a really
        // big image we'll scale it down to fit reasonably within the editor
        // itself, and within the theme's content width if it's known. The user
        // can resize it in the editor if they wish.
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        if (intval($content_width) > 0 && 'edit' == $context) {
            // Only in admin. Assume that theme authors know what they're doing.
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        $max_width = $width;
        $max_height = $height;
    }
    /**
     * Filter the maximum image size dimensions for the editor.
     *
     * @since 2.5.0
     *
     * @param array        $max_image_size An array with the width as the first element,
     *                                     and the height as the second element.
     * @param string|array $size           Size of what the result image should be.
     * @param string       $context        The context the image is being resized for.
     *                                     Possible values are 'display' (like in a theme)
     *                                     or 'edit' (like inserting into an editor).
     */
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}

WordPress Version: 3.7

/**
 * WordPress API for media display.
 *
 * @package WordPress
 * @subpackage Media
 */
/**
 * 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.
 *
 * @since 2.5.0
 * @uses wp_constrain_dimensions() This function passes the widths and the heights.
 *
 * @param int $width Width of the image
 * @param int $height Height of the image
 * @param string|array $size Size of what the result image should be.
 * @param context Could be 'display' (like in a theme) or 'edit' (like inserting into an editor)
 * @return array Width and height of what the result image should resize to.
 */
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') {
        $max_width = intval(get_option('medium_size_w'));
        $max_height = intval(get_option('medium_size_h'));
        // if no width is set, default to the theme content width if available
    } elseif ($size == 'large') {
        // We're inserting a large size image into the editor. If it's a really
        // big image we'll scale it down to fit reasonably within the editor
        // itself, and within the theme's content width if it's known. The user
        // can resize it in the editor if they wish.
        $max_width = intval(get_option('large_size_w'));
        $max_height = intval(get_option('large_size_h'));
        if (intval($content_width) > 0) {
            $max_width = min(intval($content_width), $max_width);
        }
    } elseif (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) {
        $max_width = intval($_wp_additional_image_sizes[$size]['width']);
        $max_height = intval($_wp_additional_image_sizes[$size]['height']);
        if (intval($content_width) > 0 && 'edit' == $context) {
            // Only in admin. Assume that theme authors know what they're doing.
            $max_width = min(intval($content_width), $max_width);
        }
    } else {
        $max_width = $width;
        $max_height = $height;
    }
    list($max_width, $max_height) = apply_filters('editor_max_image_size', array($max_width, $max_height), $size, $context);
    return wp_constrain_dimensions($width, $height, $max_width, $max_height);
}