WP_Image_Editor_GD::multi_resize( array $sizes )

Resize multiple images from a single source.


Parameters

$sizes

(array) (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.


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();
		$orig_size = $this->size;

		foreach ( $sizes as $size => $size_data ) {
			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;
			}

			$image = $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( $image ) && ! $duplicate ) {
				$resized = $this->_save( $image );

				imagedestroy( $image );

				if ( ! is_wp_error( $resized ) && $resized ) {
					unset( $resized['path'] );
					$metadata[$size] = $resized;
				}
			}

			$this->size = $orig_size;
		}

		return $metadata;
	}


Changelog

Changelog
Version Description
WP-3.5.0 Introduced.