WP_Image_Editor_Imagick::multi_resize( array $sizes )
Resize multiple images from a single source.
Parameters
- $sizes
-
(Required) An array of image size arrays. Default sizes are 'small', 'medium', 'medium_large', 'large'. 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.
- 'size'
(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.
- 'width'
- 'size'
Return
(array) An array of resized images' metadata by size.
Source
File: wp-includes/class-wp-image-editor-imagick.php
public function multi_resize( $sizes ) {
$metadata = array();
$orig_size = $this->size;
$orig_image = $this->image->getImage();
foreach ( $sizes as $size => $size_data ) {
if ( ! $this->image )
$this->image = $orig_image->getImage();
if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) {
continue;
}
if ( ! isset( $size_data['width'] ) ) {
$size_data['width'] = null;
}
if ( ! isset( $size_data['height'] ) ) {
$size_data['height'] = null;
}
if ( ! isset( $size_data['crop'] ) ) {
$size_data['crop'] = false;
}
$resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
$duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) );
if ( ! is_wp_error( $resize_result ) && ! $duplicate ) {
$resized = $this->_save( $this->image );
$this->image->clear();
$this->image->destroy();
$this->image = null;
if ( ! is_wp_error( $resized ) && $resized ) {
unset( $resized['path'] );
$metadata[$size] = $resized;
}
}
$this->size = $orig_size;
}
$this->image = $orig_image;
return $metadata;
}
Changelog
Version | Description |
---|---|
WP-3.5.0 | Introduced. |