Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks

Product_Image::extract_image_widthprivateWC 1.0

Extract image width from HTML for positioning calculations.

Method of the class: Product_Image{}

No Hooks.

Returns

float. Image width in pixels.

Usage

// private - for code of main (parent) class only
$result = $this->extract_image_width( $image_html ): float;
$image_html(string) (required)
Image HTML.

Product_Image::extract_image_width() code WC 10.4.3

private function extract_image_width( string $image_html ): float {
	$width = ( new Dom_Document_Helper( $image_html ) )->get_attribute_value_by_tag_name( 'img', 'width' ) ?? '';
	if ( $width ) {
		return Styles_Helper::parse_value( $width );
	}

	return 300;
}