Automattic\WooCommerce\Blocks\AIContent

ContentProcessor::adjust_image_size()public staticWC 1.0

Adjust the size of images for optimal performance on products and patterns.

Method of the class: ContentProcessor{}

No Hooks.

Return

String.

Usage

$result = ContentProcessor::adjust_image_size( $image_url, $usage_type );
$image_url(string) (required)
The image URL.
$usage_type(string) (required)
The usage type of the image. Either 'products' or 'patterns'.

ContentProcessor::adjust_image_size() code WC 9.8.1

public static function adjust_image_size( $image_url, $usage_type ) {
	$parsed_url = wp_parse_url( $image_url );

	if ( ! isset( $parsed_url['query'] ) ) {
		return $image_url;
	}

	$width = 'products' === $usage_type ? 400 : 500;

	parse_str( $parsed_url['query'], $query_params );

	unset( $query_params['h'], $query_params['w'] );
	$query_params['w'] = $width;
	$url               = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path'];

	return add_query_arg( $query_params, $url );
}