Create an image sub-size and return the image meta data value for it.
Parameters
$size_data
arrayrequired- Array of size data.
width
intThe maximum width in pixels.height
intThe maximum height in pixels.crop
bool|arrayWhether to crop the image to exact dimensions.
Source
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;
}
Changelog
Version | Description |
---|---|
5.3.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.