WP_Image_Editor_Imagick::update_size( int $width = null, int $height = null ): true|WP_Error

In this article

Sets or updates current image size.

Parameters

$widthintoptional

Default:null

$heightintoptional

Default:null

Return

true|WP_Error

Source

protected function update_size( $width = null, $height = null ) {
	$size = null;
	if ( ! $width || ! $height ) {
		try {
			$size = $this->image->getImageGeometry();
		} catch ( Exception $e ) {
			return new WP_Error( 'invalid_image', __( 'Could not read image size.' ), $this->file );
		}
	}

	if ( ! $width ) {
		$width = $size['width'];
	}

	if ( ! $height ) {
		$height = $size['height'];
	}

	/*
	 * If we still don't have the image size, fall back to `wp_getimagesize`. This ensures AVIF images
	 * are properly sized without affecting previous `getImageGeometry` behavior.
	 */
	if ( ( ! $width || ! $height ) && 'image/avif' === $this->mime_type ) {
		$size   = wp_getimagesize( $this->file );
		$width  = $size[0];
		$height = $size[1];
	}

	return parent::update_size( $width, $height );
}

Changelog

VersionDescription
3.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.