On this page
image_make_intermediate_size( string $file, int $width, int $height, bool $crop = false ): array|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.
Parameters
$filestring Required-
File path.
$widthint Required-
Image width.
$heightint Required-
Image height.
$cropbool Optional-
Whether to crop image to specified width and height or resize.
Default:
false
Return
array|false Metadata array on success. False if no image was created.
Source
File: wp-includes/media.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_get_image_editor() wp-includes/media.php | Returns a WP_Image_Editor instance and loads file into it. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/image_make_intermediate_size