You are here

function _collageformatter_layout_box in Collage Formatter 7

Recursive function to build the layout.

Parameters

$type: boolean - TRUE for portrait (horizontal contact - vertical box type); FALSE for landscape (vertical contact - horizontal box type).

1 call to _collageformatter_layout_box()
collageformatter_render_collage in ./collageformatter.module
Returns renderable array of collages.

File

./collageformatter.module, line 542
Main file for Collage Formatter module.

Code

function _collageformatter_layout_box($images, $type) {
  $box = array();
  $count = count($images);
  if ($count >= 2) {
    $size1 = floor($count / 2);
    $size2 = $count - $size1;
    $images1 = array_slice($images, 0, $size1);
    $images2 = array_slice($images, $size1, $size2);
    $box = array(
      'box_type' => 'box',
      'box_orientation' => $type ? 'vertical' : 'horizontal',
      'pixel_check' => FALSE,
    );
    $box[1] = _collageformatter_layout_box($images1, !$type);
    $box[2] = _collageformatter_layout_box($images2, !$type);
    $box[1]['parent_box_orientation'] = $box[2]['parent_box_orientation'] = $box['box_orientation'];
    $box[1]['pixel_check'] = FALSE;
    $box[2]['pixel_check'] = TRUE;
    if ($type) {

      // Horizontal contact; vertical box type.
      $dimensions = array(
        'width' => $box[1]['total_width'],
      );
    }
    else {

      // Vertical contact; horizontal box type.
      $dimensions = array(
        'height' => $box[1]['total_height'],
      );
    }
    $box[2] = _collageformatter_scale_box($box[2], $dimensions);
    if ($type) {

      // Horizontal contact; vertical box type.
      $box['total_height'] = $box[1]['total_height'] + $box[2]['total_height'];
      $box['total_width'] = $box[1]['total_width'];
    }
    else {

      // Vertical contact; horizontal box type.
      $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'];
  }
  elseif ($count == 1) {
    $box = array_pop($images);
    $box['pixel_check'] = FALSE;
  }
  return $box;
}