WP_Image_Editor_Imagick::multi_resize() WordPress Method

The WP_Image_Editor_Imagick::multi_resize() function allows you to resize an image to multiple sizes at once. This is useful for creating responsive images, or for creating different sizes of the same image for different purposes. The function takes an array of size objects, each of which contains a width and height, and an optional crop value. The crop value is a boolean, and if set to true, the image will be cropped to fit the specified size. If no crop value is specified, the image will be resized to fit within the specified size.

WP_Image_Editor_Imagick::multi_resize( array $sizes ) #

Create multiple smaller images from a single source.


Description

Attempts to create all sub-sizes and returns the meta data at the end. This may result in the server running out of resources. When it fails there may be few "orphaned" images left over as the meta data is never returned and saved.

As of 5.3.0 the preferred way to do this is with make_subsize(). It creates the new images one at a time and allows for the meta data to be saved after each new image is created.


Top ↑

Parameters

$sizes

(array)(Required)An array of image size data arrays. Either a height or width must be provided. If one of the two is set to null, the resize will maintain aspect ratio according to the provided dimension.

  • '...$0'
    (array) Array of height, width values, and whether to crop.
    • 'width'
      (int) Image width. Optional if $height is specified.
    • 'height'
      (int) Image height. Optional if $width is specified.
    • 'crop'
      (bool) Optional. Whether to crop the image. Default false.


Top ↑

Return

(array) An array of resized images' metadata by size.


Top ↑

Source

File: wp-includes/class-wp-image-editor-imagick.php

	public function multi_resize( $sizes ) {
		$metadata = array();

		foreach ( $sizes as $size => $size_data ) {
			$meta = $this->make_subsize( $size_data );

			if ( ! is_wp_error( $meta ) ) {
				$metadata[ $size ] = $meta;
			}
		}

		return $metadata;
	}


Top ↑

Changelog

Changelog
VersionDescription
3.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.