image_make_intermediate_size()WP 2.5.0

Resizes an image to make a thumbnail or intermediate size.

The returned array has the file size, the image width, and image height. The image_make_intermediate_size filter can be used to hook in and change the values of the returned array. The only parameter is the resized file path.

Хуков нет.

Возвращает

Массив|false. Metadata array on success. False if no image was created.

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

image_make_intermediate_size( $file, $width, $height, $crop );
$file(строка) (обязательный)
File path.
$width(int) (обязательный)
Image width.
$height(int) (обязательный)
Image height.
$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'.

Список изменений

С версии 2.5.0 Введена.

Код image_make_intermediate_size() WP 6.5.3

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