WP_Image_Editor_GD::_resize()protectedWP 1.0

Метод класса: WP_Image_Editor_GD{}

Хуков нет.

Возвращает

resource|GdImage|WP_Error.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->_resize( $max_w, $max_h, $crop );
$max_w(int) (обязательный)
-
$max_h(int) (обязательный)
-
$crop(true|false|массив)

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:

По умолчанию: false

  • 0(строка)
    The x crop position. Accepts 'left' 'center', or 'right'.

  • 1(строка)
    The y crop position. Accepts 'top', 'center', or 'bottom'.

Код WP_Image_Editor_GD::_resize() WP 6.5.2

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