You are here

function _collageformatter_scale_box in Collage Formatter 7

Recursive function to scale the box using only one dimension.

2 calls to _collageformatter_scale_box()
collageformatter_render_collage in ./collageformatter.module
Returns renderable array of collages.
_collageformatter_layout_box in ./collageformatter.module
Recursive function to build the layout.

File

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

Code

function _collageformatter_scale_box($box, $dimensions) {

  // If it is an image - just scale it (change dimensions).
  if ($box['box_type'] == 'image') {
    if (array_key_exists('width', $dimensions)) {
      $box['total_height'] = $dimensions['width'] / $box['total_width'] * $box['total_height'];
      $box['total_width'] = $dimensions['width'];
    }
    elseif (array_key_exists('height', $dimensions)) {
      $box['total_width'] = $dimensions['height'] / $box['total_height'] * $box['total_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 scale them.
  if (array_key_exists('width', $dimensions)) {

    // Vertical box type; horizontal contact.
    if ($box['box_orientation'] == 'vertical') {
      $dimensions1 = $dimensions2 = $dimensions;
    }
    elseif ($box['box_orientation'] == 'horizontal') {
      $dimensions1 = array(
        'width' => $box[1]['total_width'] / ($box[1]['total_width'] + $box[2]['total_width']) * $dimensions['width'],
      );
      $dimensions2 = array(
        'width' => $box[2]['total_width'] / ($box[1]['total_width'] + $box[2]['total_width']) * $dimensions['width'],
      );
    }
  }
  elseif (array_key_exists('height', $dimensions)) {

    // Vertical box type; horizontal contact.
    if ($box['box_orientation'] == 'vertical') {
      $dimensions1 = array(
        'height' => $box[1]['total_height'] / ($box[1]['total_height'] + $box[2]['total_height']) * $dimensions['height'],
      );
      $dimensions2 = array(
        'height' => $box[2]['total_height'] / ($box[1]['total_height'] + $box[2]['total_height']) * $dimensions['height'],
      );
    }
    elseif ($box['box_orientation'] == 'horizontal') {
      $dimensions1 = $dimensions2 = $dimensions;
    }
  }
  $box[1] = _collageformatter_scale_box($box[1], $dimensions1);
  $box[2] = _collageformatter_scale_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;
}