On this page
WP_Image_Editor_GD::make_subsize( array $size_data ): array|WP_Error
Create an image sub-size and return the image meta data value for it.
Parameters
$size_dataarray Required-
Array of size data.
widthintThe maximum width in pixels.heightintThe maximum height in pixels.cropboolWhether to crop the image to exact dimensions.
Return
array|WP_Error The image data array for inclusion in the sizes array in the image meta, WP_Error object on error.
Source
File: wp-includes/class-wp-image-editor-gd.php. View all references
public function make_subsize( $size_data ) {
if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) {
return new WP_Error( 'image_subsize_create_error', __( 'Cannot resize the image. Both width and height are not set.' ) );
}
$orig_size = $this->size;
if ( ! isset( $size_data['width'] ) ) {
$size_data['width'] = null;
}
if ( ! isset( $size_data['height'] ) ) {
$size_data['height'] = null;
}
if ( ! isset( $size_data['crop'] ) ) {
$size_data['crop'] = false;
}
$resized = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
if ( is_wp_error( $resized ) ) {
$saved = $resized;
} else {
$saved = $this->_save( $resized );
imagedestroy( $resized );
}
$this->size = $orig_size;
if ( ! is_wp_error( $saved ) ) {
unset( $saved['path'] );
}
return $saved;
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Image_Editor_GD::_save() wp-includes/class-wp-image-editor-gd.php | |
| WP_Image_Editor_GD::_resize() wp-includes/class-wp-image-editor-gd.php | |
| __() 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_GD::multi_resize() wp-includes/class-wp-image-editor-gd.php | Create multiple smaller images from a single source. |
Changelog
| Version | Description |
|---|---|
| 5.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_image_editor_gd/make_subsize