WC_Regenerate_Images::get_image()private staticWC 1.0

Generate the thumbnail filename and dimensions for a given file.

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

Хуков нет.

Возвращает

Массив|false. An array of the filename, thumbnail width, and thumbnail height, or false on failure to resize such as the thumbnail being larger than the fullsize image.

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

$result = WC_Regenerate_Images::get_image( $fullsizepath, $thumbnail_width, $thumbnail_height, $crop );
$fullsizepath(строка) (обязательный)
Path to full size image.
$thumbnail_width(int) (обязательный)
The width of the thumbnail.
$thumbnail_height(int) (обязательный)
The height of the thumbnail.
$crop(true|false) (обязательный)
Whether to crop or not.

Код WC_Regenerate_Images::get_image() WC 8.7.0

private static function get_image( $fullsizepath, $thumbnail_width, $thumbnail_height, $crop ) {
	list( $fullsize_width, $fullsize_height ) = getimagesize( $fullsizepath );

	$dimensions = image_resize_dimensions( $fullsize_width, $fullsize_height, $thumbnail_width, $thumbnail_height, $crop );
	$editor     = wp_get_image_editor( $fullsizepath );

	if ( is_wp_error( $editor ) ) {
		return false;
	}

	if ( ! $dimensions || ! is_array( $dimensions ) ) {
		return false;
	}

	list( , , , , $dst_w, $dst_h ) = $dimensions;
	$suffix                        = "{$dst_w}x{$dst_h}";
	$file_ext                      = strtolower( pathinfo( $fullsizepath, PATHINFO_EXTENSION ) );

	return array(
		'filename' => $editor->generate_filename( $suffix, null, $file_ext ),
		'width'    => $dst_w,
		'height'   => $dst_h,
	);
}