WP_Image_Editor_GD::_resize() WordPress Method

The WP_Image_Editor_GD::_resize() function is used to resize an image using the GD library. This is a low-level function that is used by other methods in the class.

WP_Image_Editor_GD::_resize( int $max_w, int $max_h, bool|array $crop = false ) #


Parameters

$max_w

(int)(Required)

$max_h

(int)(Required)

$crop

(bool|array)(Optional)

Default value: false


Top ↑

Return

(resource|GdImage|WP_Error)


Top ↑

Source

File: wp-includes/class-wp-image-editor-gd.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;

		$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 );
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.