WP_Image_Editor::resize( int|null $max_w, int|null $max_h, bool|array $crop = false ): true|WP_Error

Resizes current image.

Description

At minimum, 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.

Parameters

$max_wint|nullrequired
Image width.
$max_hint|nullrequired
Image height.
$cropbool|arrayoptional
Image cropping behavior. If false, the image will be scaled (default).
If true, image will be cropped to the specified dimensions using center positions.
If an array, the image will be cropped using the array to specify the crop location:
  • string
    The x crop position. Accepts 'left' 'center', or 'right'.
  • 1 string
    The y crop position. Accepts 'top', 'center', or 'bottom'.

Default:false

Return

true|WP_Error

More Information

Crop value:

  1. If false (default), images will not be cropped.
  2. If an array in the form of array( x_crop_position, y_crop_position ):
    – x_crop_position accepts ‘left’ ‘center’, or ‘right’.
    – y_crop_position accepts ‘top’, ‘center’, or ‘bottom’.
  3. Images will be cropped to the specified dimensions within the defined crop area.
  4. If true, images will be cropped to the specified dimensions using center p.

Source

abstract public function resize( $max_w, $max_h, $crop = false );

Changelog

VersionDescription
3.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.