image_make_intermediate_size() WordPress Function

The image_make_intermediate_size() function is used to create a new image file with intermediate size and quality settings. This function can be used when an image is uploaded or when a new image is created with image_resize().

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

Resizes an image to make a thumbnail or intermediate size.


Description

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.


Top ↑

Parameters

$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


Top ↑

Return

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


Top ↑

Source

File: wp-includes/media.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More