You are here

function _collageformatter_resize_box in Collage Formatter 7

Recursive function to resize the box.

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

File

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

Code

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 = array(
      'width' => $dimensions['width'],
      'height' => $box[1]['total_height'] / ($box[1]['total_height'] + $box[2]['total_height']) * $dimensions['height'],
    );
    $dimensions2 = array(
      'width' => $dimensions['width'],
      'height' => $box[2]['total_height'] / ($box[1]['total_height'] + $box[2]['total_height']) * $dimensions['height'],
    );
  }
  elseif ($box['box_orientation'] == 'horizontal') {
    $dimensions1 = array(
      'width' => $box[1]['total_width'] / ($box[1]['total_width'] + $box[2]['total_width']) * $dimensions['width'],
      'height' => $dimensions['height'],
    );
    $dimensions2 = array(
      'width' => $box[2]['total_width'] / ($box[1]['total_width'] + $box[2]['total_width']) * $dimensions['width'],
      'height' => $dimensions['height'],
    );
  }
  $box[1] = _collageformatter_resize_box($box[1], $dimensions1);
  $box[2] = _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;
}