image_make_intermediate_size

函数
image_make_intermediate_size ( $file, $width, $height, $crop = false )
参数
  • (string) $file File path.
    Required:
  • (int) $width Image width.
    Required:
  • (int) $height Image height.
    Required:
  • (bool) $crop Optional. Whether to crop image to specified width and height or resize. Default false.
    Required:
    Default: false
返回值
  • (array|false) Metadata array on success. False if no image was created.
定义位置
相关方法
image_get_intermediate_sizeget_intermediate_image_sizesimage_resizewp_make_link_relativewp_image_matches_ratio
引入
2.5.0
弃用
-

调整一个图像的大小,使其成为一个缩略图或中间尺寸。

返回的数组有文件大小、图像宽度和图像高度。{@see ‘image_make_intermediate_size’}过滤器可以用来钩住并改变返回数组的值。唯一的参数是调整后的文件路径。

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

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

		$resized_file = $editor->save();

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