A WordPress-centric search engine for devs and theme authors



image_make_intermediate_size ›

Since2.5.0
Deprecatedn/a
image_make_intermediate_size ( $file, $width, $height, $crop = false )
Parameters: (4)
  • (string) file File path.
    Required: Yes
  • (int) width Image width.
    Required: Yes
  • (int) height Image height.
    Required: Yes
  • (bool) crop Optional. Whether to crop image to specified width and height or resize. Default false.
    Required: No
    Default: false
Returns:
  • (array|bool) Metadata array on success. False if no image was created.
Defined at:
Codex:

Resizes an image to make a thumbnail or intermediate size.

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


Source

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