WP_Image_Editor::resize() WordPress Method

The WP_Image_Editor::resize() function is a great way to resize images in WordPress. It allows you to set the width and height of an image, and then WordPress will automatically resize the image to fit those dimensions. This is a great way to ensure that your images are the correct size for your website.

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

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.


Top ↑

Parameters

$max_w

(int|null)(Required)Image width.

$max_h

(int|null)(Required)Image height.

$crop

(bool)(Optional)

Default value: false


Top ↑

Return

(true|WP_Error)


Top ↑

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’.
Images will be cropped to the specified dimensions within the defined crop area.
3. If true, images will be cropped to the specified dimensions using center p


Top ↑

Source

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

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

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.