Automattic\WooCommerce\Blocks\AIContent

ContentProcessor::adjust_image_size()public staticWC 1.0

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

Метод класса: ContentProcessor{}

Хуков нет.

Возвращает

Строку.

Использование

$result = ContentProcessor::adjust_image_size( $image_url, $usage_type );
$image_url(строка) (обязательный)
The image URL.
$usage_type(строка) (обязательный)
The usage type of the image. Either 'products' or 'patterns'.

Код ContentProcessor::adjust_image_size() WC 9.5.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 );
}