GC_Image_Editor_GD::resize()

最后更新于:2021-11-27 23:39:03

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

Resizes current image.

参数

$max_w

(int|null) (Required) Image width.

$max_h

(int|null) (Required) Image height.

$crop

(bool) (Optional)

Default value: false

响应

(true|GC_Error)

源文件

文件: gc-includes/class-gc-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_gd_image( $resized ) ) {
			imagedestroy( $this->image );
			$this->image = $resized;
			return true;

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

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