image_resize_dimensions

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

WordPress Version: 6.4

/**
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   {
 *     Optional. Image cropping behavior. If false, the image will be scaled (default).
 *     If true, image will be cropped to the specified dimensions using center positions.
 *     If an array, the image will be cropped using the array to specify the crop location:
 *
 *     @type string $0 The x crop position. Accepts 'left' 'center', or 'right'.
 *     @type string $1 The y crop position. Accepts 'top', 'center', or 'bottom'.
 * }
 * @return array|false Returned array matches parameters for `imagecopyresampled()`. False on failure.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // At least one of $dest_w or $dest_h must be specific.
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filters whether to preempt calculating the image resize dimensions.
     *
     * Returning a non-null value from the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified width and height or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    // Stop if the destination size is larger than the original image dimensions.
    if (empty($dest_h)) {
        if ($orig_w < $dest_w) {
            return false;
        }
    } elseif (empty($dest_w)) {
        if ($orig_h < $dest_h) {
            return false;
        }
    } else if ($orig_w < $dest_w && $orig_h < $dest_h) {
        return false;
    }
    if ($crop) {
        /*
         * Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h.
         * Note that the requested crop dimensions are used as a maximum bounding box for the original image.
         * If the original image's width or height is less than the requested width or height
         * only the greater one will be cropped.
         * For example when the original image is 600x300, and the requested crop dimensions are 400x400,
         * the resulting image will be 400x300.
         */
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = (int) round($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = (int) round($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // Resize using $dest_w x $dest_h as a maximum bounding box.
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    if (wp_fuzzy_number_match($new_w, $orig_w) && wp_fuzzy_number_match($new_h, $orig_h)) {
        // The new size has virtually the same dimensions as the original image.
        /**
         * Filters whether to proceed with making an image sub-size with identical dimensions
         * with the original/source image. Differences of 1px may be due to rounding and are ignored.
         *
         * @since 5.3.0
         *
         * @param bool $proceed The filtered value.
         * @param int  $orig_w  Original image width.
         * @param int  $orig_h  Original image height.
         */
        $proceed = (bool) apply_filters('wp_image_resize_identical_dimensions', false, $orig_w, $orig_h);
        if (!$proceed) {
            return false;
        }
    }
    /*
     * The return array matches the parameters to imagecopyresampled().
     * int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
     */
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 6.3

/**
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * Cropping behavior is dependent on the value of $crop:
 * 1. If false (default), images will not be cropped.
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
 *    - x_crop_position accepts 'left' 'center', or 'right'.
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
 *    Images will be cropped to the specified dimensions within the defined crop area.
 * 3. If true, images will be cropped to the specified dimensions using center positions.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   Optional. Whether to crop image to specified width and height or resize.
 *                           An array can specify positioning of the crop area. Default false.
 * @return array|false Returned array matches parameters for `imagecopyresampled()`. False on failure.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // At least one of $dest_w or $dest_h must be specific.
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filters whether to preempt calculating the image resize dimensions.
     *
     * Returning a non-null value from the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified width and height or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    // Stop if the destination size is larger than the original image dimensions.
    if (empty($dest_h)) {
        if ($orig_w < $dest_w) {
            return false;
        }
    } elseif (empty($dest_w)) {
        if ($orig_h < $dest_h) {
            return false;
        }
    } else if ($orig_w < $dest_w && $orig_h < $dest_h) {
        return false;
    }
    if ($crop) {
        /*
         * Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h.
         * Note that the requested crop dimensions are used as a maximum bounding box for the original image.
         * If the original image's width or height is less than the requested width or height
         * only the greater one will be cropped.
         * For example when the original image is 600x300, and the requested crop dimensions are 400x400,
         * the resulting image will be 400x300.
         */
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = (int) round($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = (int) round($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // Resize using $dest_w x $dest_h as a maximum bounding box.
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    if (wp_fuzzy_number_match($new_w, $orig_w) && wp_fuzzy_number_match($new_h, $orig_h)) {
        // The new size has virtually the same dimensions as the original image.
        /**
         * Filters whether to proceed with making an image sub-size with identical dimensions
         * with the original/source image. Differences of 1px may be due to rounding and are ignored.
         *
         * @since 5.3.0
         *
         * @param bool $proceed The filtered value.
         * @param int  $orig_w  Original image width.
         * @param int  $orig_h  Original image height.
         */
        $proceed = (bool) apply_filters('wp_image_resize_identical_dimensions', false, $orig_w, $orig_h);
        if (!$proceed) {
            return false;
        }
    }
    /*
     * The return array matches the parameters to imagecopyresampled().
     * int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
     */
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 5.5

/**
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * Cropping behavior is dependent on the value of $crop:
 * 1. If false (default), images will not be cropped.
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
 *    - x_crop_position accepts 'left' 'center', or 'right'.
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
 *    Images will be cropped to the specified dimensions within the defined crop area.
 * 3. If true, images will be cropped to the specified dimensions using center positions.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   Optional. Whether to crop image to specified width and height or resize.
 *                           An array can specify positioning of the crop area. Default false.
 * @return array|false Returned array matches parameters for `imagecopyresampled()`. False on failure.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // At least one of $dest_w or $dest_h must be specific.
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filters whether to preempt calculating the image resize dimensions.
     *
     * Returning a non-null value from the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified width and height or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    // Stop if the destination size is larger than the original image dimensions.
    if (empty($dest_h)) {
        if ($orig_w < $dest_w) {
            return false;
        }
    } elseif (empty($dest_w)) {
        if ($orig_h < $dest_h) {
            return false;
        }
    } else if ($orig_w < $dest_w && $orig_h < $dest_h) {
        return false;
    }
    if ($crop) {
        /*
         * Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h.
         * Note that the requested crop dimensions are used as a maximum bounding box for the original image.
         * If the original image's width or height is less than the requested width or height
         * only the greater one will be cropped.
         * For example when the original image is 600x300, and the requested crop dimensions are 400x400,
         * the resulting image will be 400x300.
         */
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = (int) round($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = (int) round($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // Resize using $dest_w x $dest_h as a maximum bounding box.
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    if (wp_fuzzy_number_match($new_w, $orig_w) && wp_fuzzy_number_match($new_h, $orig_h)) {
        // The new size has virtually the same dimensions as the original image.
        /**
         * Filters whether to proceed with making an image sub-size with identical dimensions
         * with the original/source image. Differences of 1px may be due to rounding and are ignored.
         *
         * @since 5.3.0
         *
         * @param bool $proceed The filtered value.
         * @param int  $orig_w  Original image width.
         * @param int  $orig_h  Original image height.
         */
        $proceed = (bool) apply_filters('wp_image_resize_identical_dimensions', false, $orig_w, $orig_h);
        if (!$proceed) {
            return false;
        }
    }
    // The return array matches the parameters to imagecopyresampled().
    // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 5.4

/**
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * Cropping behavior is dependent on the value of $crop:
 * 1. If false (default), images will not be cropped.
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
 *    - x_crop_position accepts 'left' 'center', or 'right'.
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
 *    Images will be cropped to the specified dimensions within the defined crop area.
 * 3. If true, images will be cropped to the specified dimensions using center positions.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   Optional. Whether to crop image to specified width and height or resize.
 *                           An array can specify positioning of the crop area. Default false.
 * @return array|false Returned array matches parameters for `imagecopyresampled()`. False on failure.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // At least one of $dest_w or $dest_h must be specific.
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filters whether to preempt calculating the image resize dimensions.
     *
     * Passing a non-null value to the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified width and height or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    // Stop if the destination size is larger than the original image dimensions.
    if (empty($dest_h)) {
        if ($orig_w < $dest_w) {
            return false;
        }
    } elseif (empty($dest_w)) {
        if ($orig_h < $dest_h) {
            return false;
        }
    } else if ($orig_w < $dest_w && $orig_h < $dest_h) {
        return false;
    }
    if ($crop) {
        /*
         * Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h.
         * Note that the requested crop dimensions are used as a maximum bounding box for the original image.
         * If the original image's width or height is less than the requested width or height
         * only the greater one will be cropped.
         * For example when the original image is 600x300, and the requested crop dimensions are 400x400,
         * the resulting image will be 400x300.
         */
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = (int) round($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = (int) round($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // Resize using $dest_w x $dest_h as a maximum bounding box.
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    if (wp_fuzzy_number_match($new_w, $orig_w) && wp_fuzzy_number_match($new_h, $orig_h)) {
        // The new size has virtually the same dimensions as the original image.
        /**
         * Filters whether to proceed with making an image sub-size with identical dimensions
         * with the original/source image. Differences of 1px may be due to rounding and are ignored.
         *
         * @since 5.3.0
         *
         * @param bool $proceed The filtered value.
         * @param int  $orig_w  Original image width.
         * @param int  $orig_h  Original image height.
         */
        $proceed = (bool) apply_filters('wp_image_resize_identical_dimensions', false, $orig_w, $orig_h);
        if (!$proceed) {
            return false;
        }
    }
    // The return array matches the parameters to imagecopyresampled().
    // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 5.3

/**
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * Cropping behavior is dependent on the value of $crop:
 * 1. If false (default), images will not be cropped.
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
 *    - x_crop_position accepts 'left' 'center', or 'right'.
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
 *    Images will be cropped to the specified dimensions within the defined crop area.
 * 3. If true, images will be cropped to the specified dimensions using center positions.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   Optional. Whether to crop image to specified width and height or resize.
 *                           An array can specify positioning of the crop area. Default false.
 * @return false|array False on failure. Returned array matches parameters for `imagecopyresampled()`.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // at least one of dest_w or dest_h must be specific
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filters whether to preempt calculating the image resize dimensions.
     *
     * Passing a non-null value to the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified width and height or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    // Stop if the destination size is larger than the original image dimensions.
    if (empty($dest_h)) {
        if ($orig_w < $dest_w) {
            return false;
        }
    } elseif (empty($dest_w)) {
        if ($orig_h < $dest_h) {
            return false;
        }
    } else if ($orig_w < $dest_w && $orig_h < $dest_h) {
        return false;
    }
    if ($crop) {
        // Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h.
        // Note that the requested crop dimensions are used as a maximum bounding box for the original image.
        // If the original image's width or height is less than the requested width or height
        // only the greater one will be cropped.
        // For example when the original image is 600x300, and the requested crop dimensions are 400x400,
        // the resulting image will be 400x300.
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = (int) round($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = (int) round($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // Resize using $dest_w x $dest_h as a maximum bounding box.
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    if (wp_fuzzy_number_match($new_w, $orig_w) && wp_fuzzy_number_match($new_h, $orig_h)) {
        // The new size has virtually the same dimensions as the original image.
        /**
         * Filters whether to proceed with making an image sub-size with identical dimensions
         * with the original/source image. Differences of 1px may be due to rounding and are ignored.
         *
         * @since 5.3.0
         *
         * @param bool The filtered value.
         * @param int  Original image width.
         * @param int  Original image height.
         */
        $proceed = (bool) apply_filters('wp_image_resize_identical_dimensions', false, $orig_w, $orig_h);
        if (!$proceed) {
            return false;
        }
    }
    // The return array matches the parameters to imagecopyresampled().
    // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 4.6

/**
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * Cropping behavior is dependent on the value of $crop:
 * 1. If false (default), images will not be cropped.
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
 *    - x_crop_position accepts 'left' 'center', or 'right'.
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
 *    Images will be cropped to the specified dimensions within the defined crop area.
 * 3. If true, images will be cropped to the specified dimensions using center positions.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   Optional. Whether to crop image to specified width and height or resize.
 *                           An array can specify positioning of the crop area. Default false.
 * @return false|array False on failure. Returned array matches parameters for `imagecopyresampled()`.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // at least one of dest_w or dest_h must be specific
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filters whether to preempt calculating the image resize dimensions.
     *
     * Passing a non-null value to the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified width and height or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    if ($crop) {
        // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = (int) round($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = (int) round($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    // if the resulting image would be the same size or larger we don't want to resize it
    if ($new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h) {
        return false;
    }
    // the return array matches the parameters to imagecopyresampled()
    // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 4.4

/**
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * Cropping behavior is dependent on the value of $crop:
 * 1. If false (default), images will not be cropped.
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
 *    - x_crop_position accepts 'left' 'center', or 'right'.
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
 *    Images will be cropped to the specified dimensions within the defined crop area.
 * 3. If true, images will be cropped to the specified dimensions using center positions.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   Optional. Whether to crop image to specified width and height or resize.
 *                           An array can specify positioning of the crop area. Default false.
 * @return false|array False on failure. Returned array matches parameters for `imagecopyresampled()`.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // at least one of dest_w or dest_h must be specific
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filter whether to preempt calculating the image resize dimensions.
     *
     * Passing a non-null value to the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified width and height or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    if ($crop) {
        // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = (int) round($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = (int) round($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    // if the resulting image would be the same size or larger we don't want to resize it
    if ($new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h) {
        return false;
    }
    // the return array matches the parameters to imagecopyresampled()
    // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 4.3

/**
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * Cropping behavior is dependent on the value of $crop:
 * 1. If false (default), images will not be cropped.
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
 *    - x_crop_position accepts 'left' 'center', or 'right'.
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
 *    Images will be cropped to the specified dimensions within the defined crop area.
 * 3. If true, images will be cropped to the specified dimensions using center positions.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   Optional. Whether to crop image to specified height and width or resize.
 *                           An array can specify positioning of the crop area. Default false.
 * @return false|array False on failure. Returned array matches parameters for `imagecopyresampled()`.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // at least one of dest_w or dest_h must be specific
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filter whether to preempt calculating the image resize dimensions.
     *
     * Passing a non-null value to the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified height and width or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    if ($crop) {
        // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = (int) round($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = (int) round($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    // if the resulting image would be the same size or larger we don't want to resize it
    if ($new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h) {
        return false;
    }
    // the return array matches the parameters to imagecopyresampled()
    // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 4.2

/**
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * Cropping behavior is dependent on the value of $crop:
 * 1. If false (default), images will not be cropped.
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
 *    - x_crop_position accepts 'left' 'center', or 'right'.
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
 *    Images will be cropped to the specified dimensions within the defined crop area.
 * 3. If true, images will be cropped to the specified dimensions using center positions.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   Optional. Whether to crop image to specified height and width or resize.
 *                           An array can specify positioning of the crop area. Default false.
 * @return bool|array False on failure. Returned array matches parameters for `imagecopyresampled()`.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // at least one of dest_w or dest_h must be specific
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filter whether to preempt calculating the image resize dimensions.
     *
     * Passing a non-null value to the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified height and width or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    if ($crop) {
        // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = (int) round($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = (int) round($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    // if the resulting image would be the same size or larger we don't want to resize it
    if ($new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h) {
        return false;
    }
    // the return array matches the parameters to imagecopyresampled()
    // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 4.1

/**
 * Retrieve calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * Cropping behavior is dependent on the value of $crop:
 * 1. If false (default), images will not be cropped.
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
 *    - x_crop_position accepts 'left' 'center', or 'right'.
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
 *    Images will be cropped to the specified dimensions within the defined crop area.
 * 3. If true, images will be cropped to the specified dimensions using center positions.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   Optional. Whether to crop image to specified height and width or resize.
 *                           An array can specify positioning of the crop area. Default false.
 * @return bool|array False on failure. Returned array matches parameters for `imagecopyresampled()`.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // at least one of dest_w or dest_h must be specific
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filter whether to preempt calculating the image resize dimensions.
     *
     * Passing a non-null value to the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified height and width or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    if ($crop) {
        // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = (int) round($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = (int) round($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    // if the resulting image would be the same size or larger we don't want to resize it
    if ($new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h) {
        return false;
    }
    // the return array matches the parameters to imagecopyresampled()
    // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 3.9

/**
 * Retrieve calculated resize dimensions for use in WP_Image_Editor.
 *
 * Calculates dimensions and coordinates for a resized image that fits
 * within a specified width and height.
 *
 * Cropping behavior is dependent on the value of $crop:
 * 1. If false (default), images will not be cropped.
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
 *    - x_crop_position accepts 'left' 'center', or 'right'.
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
 *    Images will be cropped to the specified dimensions within the defined crop area.
 * 3. If true, images will be cropped to the specified dimensions using center positions.
 *
 * @since 2.5.0
 *
 * @param int        $orig_w Original width in pixels.
 * @param int        $orig_h Original height in pixels.
 * @param int        $dest_w New width in pixels.
 * @param int        $dest_h New height in pixels.
 * @param bool|array $crop   Optional. Whether to crop image to specified height and width or resize.
 *                           An array can specify positioning of the crop area. Default false.
 * @return bool|array False on failure. Returned array matches parameters for `imagecopyresampled()`.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // at least one of dest_w or dest_h must be specific
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    /**
     * Filter whether to preempt calculating the image resize dimensions.
     *
     * Passing a non-null value to the filter will effectively short-circuit
     * image_resize_dimensions(), returning that value instead.
     *
     * @since 3.4.0
     *
     * @param null|mixed $null   Whether to preempt output of the resize dimensions.
     * @param int        $orig_w Original width in pixels.
     * @param int        $orig_h Original height in pixels.
     * @param int        $dest_w New width in pixels.
     * @param int        $dest_h New height in pixels.
     * @param bool|array $crop   Whether to crop image to specified height and width or resize.
     *                           An array can specify positioning of the crop area. Default false.
     */
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    if ($crop) {
        // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = intval($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = intval($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        if (!is_array($crop) || count($crop) !== 2) {
            $crop = array('center', 'center');
        }
        list($x, $y) = $crop;
        if ('left' === $x) {
            $s_x = 0;
        } elseif ('right' === $x) {
            $s_x = $orig_w - $crop_w;
        } else {
            $s_x = floor(($orig_w - $crop_w) / 2);
        }
        if ('top' === $y) {
            $s_y = 0;
        } elseif ('bottom' === $y) {
            $s_y = $orig_h - $crop_h;
        } else {
            $s_y = floor(($orig_h - $crop_h) / 2);
        }
    } else {
        // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    // if the resulting image would be the same size or larger we don't want to resize it
    if ($new_w >= $orig_w && $new_h >= $orig_h) {
        return false;
    }
    // the return array matches the parameters to imagecopyresampled()
    // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}

WordPress Version: 3.7

/**
 * Retrieve calculated resized dimensions for use in WP_Image_Editor.
 *
 * Calculate dimensions and coordinates for a resized image that fits within a
 * specified width and height. If $crop is true, the largest matching central
 * portion of the image will be cropped out and resized to the required size.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'image_resize_dimensions' on $orig_w, $orig_h, $dest_w, $dest_h and
 *		$crop to provide custom resize dimensions.
 *
 * @param int $orig_w Original width.
 * @param int $orig_h Original height.
 * @param int $dest_w New width.
 * @param int $dest_h New height.
 * @param bool $crop Optional, default is false. Whether to crop image or resize.
 * @return bool|array False on failure. Returned array matches parameters for imagecopyresampled() PHP function.
 */
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false)
{
    if ($orig_w <= 0 || $orig_h <= 0) {
        return false;
    }
    // at least one of dest_w or dest_h must be specific
    if ($dest_w <= 0 && $dest_h <= 0) {
        return false;
    }
    // plugins can use this to provide custom resize dimensions
    $output = apply_filters('image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop);
    if (null !== $output) {
        return $output;
    }
    if ($crop) {
        // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if (!$new_w) {
            $new_w = intval($new_h * $aspect_ratio);
        }
        if (!$new_h) {
            $new_h = intval($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        $s_x = floor(($orig_w - $crop_w) / 2);
        $s_y = floor(($orig_h - $crop_h) / 2);
    } else {
        // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = 0;
        $s_y = 0;
        list($new_w, $new_h) = wp_constrain_dimensions($orig_w, $orig_h, $dest_w, $dest_h);
    }
    // if the resulting image would be the same size or larger we don't want to resize it
    if ($new_w >= $orig_w && $new_h >= $orig_h) {
        return false;
    }
    // the return array matches the parameters to imagecopyresampled()
    // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
    return array(0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h);
}