image_make_intermediate_size()

最后更新于:2021-11-27 06:34:05

image_make_intermediate_size( string$file, int$width, int$height, bool$crop=false)

Resizes an image to make a thumbnail or intermediate size.

参数

$file

(string) (Required) File path.

$width

(int) (Required) Image width.

$height

(int) (Required) Image height.

$crop

(bool) (Optional) Whether to crop image to specified width and height or resize.

Default value: false

响应

(array|false) Metadata array on success. False if no image was created.

源文件

文件: gc-includes/media.php

function image_make_intermediate_size( $file, $width, $height, $crop = false ) {
	if ( $width || $height ) {
		$editor = gc_get_image_editor( $file );

		if ( is_gc_error( $editor ) || is_gc_error( $editor->resize( $width, $height, $crop ) ) ) {
			return false;
		}

		$resized_file = $editor->save();

		if ( ! is_gc_error( $resized_file ) && $resized_file ) {
			unset( $resized_file['path'] );
			return $resized_file;
		}
	}
	return false;
}