image_resize

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

WordPress Version: 5.5

/**
 * Scale down an image to fit a particular size and save a new copy of the image.
 *
 * The PNG transparency will be preserved using the function, as well as the
 * image type. If the file going in is PNG, then the resized image is going to
 * be PNG. The only supported image types are PNG, GIF, and JPEG.
 *
 * Some functionality requires API to exist, so some PHP version may lose out
 * support. This is not the fault of WordPress (where functionality is
 * downgraded, not actual defects), but of your PHP version.
 *
 * @since 2.5.0
 * @deprecated 3.5.0 Use wp_get_image_editor()
 * @see wp_get_image_editor()
 *
 * @param string $file         Image file path.
 * @param int    $max_w        Maximum width to resize to.
 * @param int    $max_h        Maximum height to resize to.
 * @param bool   $crop         Optional. Whether to crop image or resize. Default false.
 * @param string $suffix       Optional. File suffix. Default null.
 * @param string $dest_path    Optional. New image file path. Default null.
 * @param int    $jpeg_quality Optional. Image quality percentage. Default 90.
 * @return mixed WP_Error on failure. String with new destination path.
 */
function image_resize($file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90)
{
    _deprecated_function(__FUNCTION__, '3.5.0', 'wp_get_image_editor()');
    $editor = wp_get_image_editor($file);
    if (is_wp_error($editor)) {
        return $editor;
    }
    $editor->set_quality($jpeg_quality);
    $resized = $editor->resize($max_w, $max_h, $crop);
    if (is_wp_error($resized)) {
        return $resized;
    }
    $dest_file = $editor->generate_filename($suffix, $dest_path);
    $saved = $editor->save($dest_file);
    if (is_wp_error($saved)) {
        return $saved;
    }
    return $dest_file;
}

WordPress Version: 4.6

/**
 * Scale down an image to fit a particular size and save a new copy of the image.
 *
 * The PNG transparency will be preserved using the function, as well as the
 * image type. If the file going in is PNG, then the resized image is going to
 * be PNG. The only supported image types are PNG, GIF, and JPEG.
 *
 * Some functionality requires API to exist, so some PHP version may lose out
 * support. This is not the fault of WordPress (where functionality is
 * downgraded, not actual defects), but of your PHP version.
 *
 * @since 2.5.0
 * @deprecated 3.5.0 Use wp_get_image_editor()
 * @see wp_get_image_editor()
 *
 * @param string $file Image file path.
 * @param int $max_w Maximum width to resize to.
 * @param int $max_h Maximum height to resize to.
 * @param bool $crop Optional. Whether to crop image or resize.
 * @param string $suffix Optional. File suffix.
 * @param string $dest_path Optional. New image file path.
 * @param int $jpeg_quality Optional, default is 90. Image quality percentage.
 * @return mixed WP_Error on failure. String with new destination path.
 */
function image_resize($file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90)
{
    _deprecated_function(__FUNCTION__, '3.5.0', 'wp_get_image_editor()');
    $editor = wp_get_image_editor($file);
    if (is_wp_error($editor)) {
        return $editor;
    }
    $editor->set_quality($jpeg_quality);
    $resized = $editor->resize($max_w, $max_h, $crop);
    if (is_wp_error($resized)) {
        return $resized;
    }
    $dest_file = $editor->generate_filename($suffix, $dest_path);
    $saved = $editor->save($dest_file);
    if (is_wp_error($saved)) {
        return $saved;
    }
    return $dest_file;
}

WordPress Version: 4.4

/**
 * Scale down an image to fit a particular size and save a new copy of the image.
 *
 * The PNG transparency will be preserved using the function, as well as the
 * image type. If the file going in is PNG, then the resized image is going to
 * be PNG. The only supported image types are PNG, GIF, and JPEG.
 *
 * Some functionality requires API to exist, so some PHP version may lose out
 * support. This is not the fault of WordPress (where functionality is
 * downgraded, not actual defects), but of your PHP version.
 *
 * @since 2.5.0
 * @deprecated 3.5.0 Use wp_get_image_editor()
 * @see wp_get_image_editor()
 *
 * @param string $file Image file path.
 * @param int $max_w Maximum width to resize to.
 * @param int $max_h Maximum height to resize to.
 * @param bool $crop Optional. Whether to crop image or resize.
 * @param string $suffix Optional. File suffix.
 * @param string $dest_path Optional. New image file path.
 * @param int $jpeg_quality Optional, default is 90. Image quality percentage.
 * @return mixed WP_Error on failure. String with new destination path.
 */
function image_resize($file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90)
{
    _deprecated_function(__FUNCTION__, '3.5', 'wp_get_image_editor()');
    $editor = wp_get_image_editor($file);
    if (is_wp_error($editor)) {
        return $editor;
    }
    $editor->set_quality($jpeg_quality);
    $resized = $editor->resize($max_w, $max_h, $crop);
    if (is_wp_error($resized)) {
        return $resized;
    }
    $dest_file = $editor->generate_filename($suffix, $dest_path);
    $saved = $editor->save($dest_file);
    if (is_wp_error($saved)) {
        return $saved;
    }
    return $dest_file;
}

WordPress Version: 3.7

/**
 * Scale down an image to fit a particular size and save a new copy of the image.
 *
 * The PNG transparency will be preserved using the function, as well as the
 * image type. If the file going in is PNG, then the resized image is going to
 * be PNG. The only supported image types are PNG, GIF, and JPEG.
 *
 * Some functionality requires API to exist, so some PHP version may lose out
 * support. This is not the fault of WordPress (where functionality is
 * downgraded, not actual defects), but of your PHP version.
 *
 * @since 2.5.0
 * @deprecated 3.5.0
 * @see wp_get_image_editor()
 *
 * @param string $file Image file path.
 * @param int $max_w Maximum width to resize to.
 * @param int $max_h Maximum height to resize to.
 * @param bool $crop Optional. Whether to crop image or resize.
 * @param string $suffix Optional. File suffix.
 * @param string $dest_path Optional. New image file path.
 * @param int $jpeg_quality Optional, default is 90. Image quality percentage.
 * @return mixed WP_Error on failure. String with new destination path.
 */
function image_resize($file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90)
{
    _deprecated_function(__FUNCTION__, '3.5', 'wp_get_image_editor()');
    $editor = wp_get_image_editor($file);
    if (is_wp_error($editor)) {
        return $editor;
    }
    $editor->set_quality($jpeg_quality);
    $resized = $editor->resize($max_w, $max_h, $crop);
    if (is_wp_error($resized)) {
        return $resized;
    }
    $dest_file = $editor->generate_filename($suffix, $dest_path);
    $saved = $editor->save($dest_file);
    if (is_wp_error($saved)) {
        return $saved;
    }
    return $dest_file;
}