WP_Image_Editor_GD::multi_resize() WordPress Method
The GD Image Editor is a popular tool for editing images within the WordPress framework. The GD library allows for a wide range of image manipulation functions, and the Image Editor provides an easy-to-use interface for performing these functions. One of the most popular features of the GD Image Editor is the ability to resize images. The Multi Resize function allows users to resize an image to multiple sizes at once, making it a quick and easy way to generate multiple versions of an image.
WP_Image_Editor_GD::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.
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 source image.
- '...$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.
- 'width'
- '...$0'
Return
(array) An array of resized images' metadata by size.
Source
File: wp-includes/class-wp-image-editor-gd.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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.5.0 | Introduced. |