function CollageFormatter::collageformatter_resize_box in Collage Formatter 8
Recursive function to resize the box.
Parameters
$box: array - array of images boxed as configured
- @param $dimensions array - array containing dimensions i.e. - width and height (if any) of the box
1 call to CollageFormatter::collageformatter_resize_box()
- CollageFormatter::collageformatter_render_collage in src/
Plugin/ Field/ FieldFormatter/ CollageFormatter.php - Returns renderable array of collages.
File
- src/
Plugin/ Field/ FieldFormatter/ CollageFormatter.php, line 717 - Contains \Drupal\collageformatter\src\Plugin\Field\FieldFormatter\CollageFormatter.
Class
- CollageFormatter
- Plugin implementation of the 'collageformatter' formatter.
Namespace
Drupal\collageformatter\Plugin\Field\FieldFormatterCode
function collageformatter_resize_box($box, $dimensions) {
// If it is an image - just resize it (change dimensions).
if ($box['box_type'] == 'image') {
$box['total_width'] = $dimensions['width'];
$box['total_height'] = $dimensions['height'];
return $box;
}
// If it is a box - then it should consist of two box elements;
// Determine sizes of elements and resize them.
// Vertical box type; horizontal contact.
if ($box['box_orientation'] == 'vertical') {
$dimensions1 = [
'width' => $dimensions['width'],
'height' => $box[1]['total_height'] / ($box[1]['total_height'] + $box[2]['total_height']) * $dimensions['height'],
];
$dimensions2 = [
'width' => $dimensions['width'],
'height' => $box[2]['total_height'] / ($box[1]['total_height'] + $box[2]['total_height']) * $dimensions['height'],
];
}
elseif ($box['box_orientation'] == 'horizontal') {
$dimensions1 = [
'width' => $box[1]['total_width'] / ($box[1]['total_width'] + $box[2]['total_width']) * $dimensions['width'],
'height' => $dimensions['height'],
];
$dimensions2 = [
'width' => $box[2]['total_width'] / ($box[1]['total_width'] + $box[2]['total_width']) * $dimensions['width'],
'height' => $dimensions['height'],
];
}
$box[1] = $this
->collageformatter_resize_box($box[1], $dimensions1);
$box[2] = $this
->collageformatter_resize_box($box[2], $dimensions2);
if ($box['box_orientation'] == 'vertical') {
$box['total_height'] = $box[1]['total_height'] + $box[2]['total_height'];
$box['total_width'] = $box[1]['total_width'];
}
elseif ($box['box_orientation'] == 'horizontal') {
$box['total_width'] = $box[1]['total_width'] + $box[2]['total_width'];
$box['total_height'] = $box[1]['total_height'];
}
$box[1]['parent_total_width'] = $box[2]['parent_total_width'] = $box['total_width'];
$box[1]['parent_total_height'] = $box[2]['parent_total_height'] = $box['total_height'];
$box[1]['siblings_total_width'] = $box[2]['total_width'];
$box[1]['siblings_total_height'] = $box[2]['total_height'];
$box[2]['siblings_total_width'] = $box[1]['total_width'];
$box[2]['siblings_total_height'] = $box[1]['total_height'];
return $box;
}