Title: WP_Image_Editor_GD::_resize
Published: April 25, 2014
Last modified: May 20, 2026

---

# WP_Image_Editor_GD::_resize( int $max_w, int $max_h, bool|array $crop = false ): resource|GdImage|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#related)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#wp--skip-link--target)

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#parameters)󠁿

 `$max_w`intrequired

`$max_h`intrequired

`$crop`bool|arrayoptional

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:

 * `0` string
 * The x crop position. Accepts `'left'`, `'center'`, or `'right'`.
 * `1` string
 * The y crop position. Accepts `'top'`, `'center'`, or `'bottom'`.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#return)󠁿

 resource|GdImage|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#source)󠁿

    ```php
    protected function _resize( $max_w, $max_h, $crop = false ) {
    	$dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop );

    	if ( ! $dims ) {
    		return new WP_Error( 'error_getting_dimensions', __( 'Could not calculate resized image dimensions' ), $this->file );
    	}

    	list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;

    	$this->set_quality(
    		null,
    		array(
    			'width'  => $dst_w,
    			'height' => $dst_h,
    		)
    	);

    	$resized = wp_imagecreatetruecolor( $dst_w, $dst_h );
    	imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );

    	if ( is_gd_image( $resized ) ) {
    		$this->update_size( $dst_w, $dst_h );
    		return $resized;
    	}

    	return new WP_Error( 'image_resize_error', __( 'Image resize failed.' ), $this->file );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-image-editor-gd.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-image-editor-gd.php#L221)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-image-editor-gd.php#L221-L247)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Image_Editor_GD::set_quality()](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/set_quality/)`wp-includes/class-wp-image-editor-gd.php` |

Sets Image Compression quality on a 1-100% scale. Handles WebP lossless images.

  | 
| [is_gd_image()](https://developer.wordpress.org/reference/functions/is_gd_image/)`wp-includes/media.php` |

Determines whether the value is an acceptable type for GD image functions.

  | 
| [WP_Image_Editor_GD::update_size()](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/update_size/)`wp-includes/class-wp-image-editor-gd.php` |

Sets or updates current image size.

  | 
| [wp_imagecreatetruecolor()](https://developer.wordpress.org/reference/functions/wp_imagecreatetruecolor/)`wp-includes/media.php` |

Creates a new GD image resource with transparency support.

  | 
| [image_resize_dimensions()](https://developer.wordpress.org/reference/functions/image_resize_dimensions/)`wp-includes/media.php` |

Retrieves calculated resize dimensions for use in [WP_Image_Editor](https://developer.wordpress.org/reference/classes/wp_image_editor/).

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 2 more](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize/?output_format=md#)

| Used by | Description | 
| [WP_Image_Editor_GD::make_subsize()](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/make_subsize/)`wp-includes/class-wp-image-editor-gd.php` |

Create an image sub-size and return the image meta data value for it.

  | 
| [WP_Image_Editor_GD::resize()](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/resize/)`wp-includes/class-wp-image-editor-gd.php` |

Resizes current image.

  |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_image_editor_gd%2F_resize%2F)
before being able to contribute a note or feedback.