On this page
WP_Image_Editor_Imagick::resize( int|null $max_w, int|null $max_h, bool $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|null Required-
Image width.
$max_hint|null Required-
Image height.
$cropbool Optional-
Default:
false
Return
true|WP_Error
Source
File: wp-includes/class-wp-image-editor-imagick.php. View all references
public function resize( $max_w, $max_h, $crop = false ) {
if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) {
return true;
}
$dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop );
if ( ! $dims ) {
return new WP_Error( 'error_getting_dimensions', __( 'Could not calculate resized image dimensions' ) );
}
list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
if ( $crop ) {
return $this->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h );
}
// Execute the resize.
$thumb_result = $this->thumbnail_image( $dst_w, $dst_h );
if ( is_wp_error( $thumb_result ) ) {
return $thumb_result;
}
return $this->update_size( $dst_w, $dst_h );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Image_Editor_Imagick::thumbnail_image() wp-includes/class-wp-image-editor-imagick.php | Efficiently resize the current image |
| WP_Image_Editor_Imagick::crop() wp-includes/class-wp-image-editor-imagick.php | Crops Image. |
| WP_Image_Editor_Imagick::update_size() wp-includes/class-wp-image-editor-imagick.php | Sets or updates current image size. |
| image_resize_dimensions() wp-includes/media.php | Retrieves calculated resize dimensions for use in WP_Image_Editor. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Used By
| Used By | Description |
|---|---|
| WP_Image_Editor_Imagick::make_subsize() wp-includes/class-wp-image-editor-imagick.php | Create an image sub-size and return the image meta data value for it. |
Changelog
| Version | Description |
|---|---|
| 3.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/resize