WP_Image_Editor_GD::resize() public WP 3.5.0
Resizes current image.
Wraps ::_resize() which returns a GD resource or GdImage instance.
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.
{} It's a method of the class: WP_Image_Editor_GD{}
No Hooks.
Return
true/WP_Error.
Usage
$WP_Image_Editor_GD = new WP_Image_Editor_GD(); $WP_Image_Editor_GD->resize( $max_w, $max_h, $crop );
- $max_w(int/null) (required)
- Image width.
- $max_h(int/null) (required)
- Image height.
- $crop(true/false)
Default: false
Changelog
Since 3.5.0 | Introduced. |
Code of WP_Image_Editor_GD::resize() WP Image Editor GD::resize WP 5.6
public function resize( $max_w, $max_h, $crop = false ) {
if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) {
return true;
}
$resized = $this->_resize( $max_w, $max_h, $crop );
if ( is_gd_image( $resized ) ) {
imagedestroy( $this->image );
$this->image = $resized;
return true;
} elseif ( is_wp_error( $resized ) ) {
return $resized;
}
return new WP_Error( 'image_resize_error', __( 'Image resize failed.' ), $this->file );
}