On this page
WP_Image_Editor_GD::_resize( int $max_w, int $max_h, bool|array $crop = false ): resource|GdImage|WP_Error
Parameters
$max_wint Required$max_hint Required$cropbool|array Optional-
Default:
false
Return
resource|GdImage|WP_Error
Source
File: wp-includes/class-wp-image-editor-gd.php. View all references
protected function _resize( $max_w, $max_h, $crop = false ) {
$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' ), $this->file );
}
list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
$resized = wp_imagecreatetruecolor( $dst_w, $dst_h );
imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
if ( is_gd_image( $resized ) ) {
$this->update_size( $dst_w, $dst_h );
return $resized;
}
return new WP_Error( 'image_resize_error', __( 'Image resize failed.' ), $this->file );
}
Related
Uses
| Uses | Description |
|---|---|
| is_gd_image() wp-includes/media.php | Determines whether the value is an acceptable type for GD image functions. |
| WP_Image_Editor_GD::update_size() wp-includes/class-wp-image-editor-gd.php | Sets or updates current image size. |
| wp_imagecreatetruecolor() wp-includes/media.php | Creates new GD image resource with transparency support. |
| 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. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Used By
| Used By | Description |
|---|---|
| WP_Image_Editor_GD::make_subsize() wp-includes/class-wp-image-editor-gd.php | Create an image sub-size and return the image meta data value for it. |
| WP_Image_Editor_GD::resize() wp-includes/class-wp-image-editor-gd.php | Resizes current image. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_image_editor_gd/_resize