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

Gallery::get_cell_width │ private │ WC 1.0

Estimate the rendered width (in px) of the gallery cell that holds a given image.

The gallery packs images into rows of $columns. A complete row splits the layout width evenly, but an incomplete final row is distributed across only its remaining images — a lone trailing image spans the full width (see {@see build_gallery_row_table()}). Sizing the crop to the actual cell keeps an image CDN from serving an undersized file for such images.

Method of the class: Gallery{}

No Hooks.

Returns

int. Cell width in px (at least 1).

Usage

// private - for code of main (parent) class only
$result = $this->get_cell_width( $index, $image_count, $columns, $layout_width ): int;
$index(int) (required)
Zero-based index of the image among the rendered images.
$image_count(int) (required)
Total number of rendered images.
$columns(int) (required)
Number of gallery columns.
$layout_width(int) (required)
Available layout width in px.

Gallery::get_cell_width() code WC 11.1.2

private function get_cell_width( int $index, int $image_count, int $columns, int $layout_width ): int {
	$columns       = max( 1, $columns );
	$row_start     = intdiv( $index, $columns ) * $columns;
	$images_in_row = max( 1, min( $columns, $image_count - $row_start ) );

	return (int) max( 1, floor( $layout_width / $images_in_row ) );
}