Summery Summery

Resizes current image.

Syntax Syntax

WP_Image_Editor_GD::resize( int|null $max_w, int|null $max_h, bool $crop = false )

Description Description

Wraps _resize, since _resize returns a GD Resource.

At minimum, either a height or width must be provided. If one of the two is set to null, the resize will maintain aspect ratio according to the provided dimension.

Parameters Parameters


(int|null) (Required) Image width.


(int|null) (Required) Image height.


(bool) (Optional)

Default value: false

Return Return


Source Source

File: wp-includes/class-wp-image-editor-gd.php

	public function resize( $max_w, $max_h, $crop = false ) {
		if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) {
			return true;

		$resized = $this->_resize( $max_w, $max_h, $crop );

		if ( is_resource( $resized ) ) {
			imagedestroy( $this->image );
			$this->image = $resized;
			return true;

		} elseif ( is_wp_error( $resized ) ) {
			return $resized;

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


Changelog Changelog

Version Description
3.5.0 Introduced.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.