function imagecache_actions_calculate_relative_position in ImageCache Actions 6
Same name and namespace in other branches
- 8 utility.inc \imagecache_actions_calculate_relative_position()
- 6.2 utility.inc \imagecache_actions_calculate_relative_position()
- 7 utility.inc \imagecache_actions_calculate_relative_position()
Given two imageapi objects with dimensions, and some positioning values, calculate a new x,y for the layer to be placed at.
1 call to imagecache_actions_calculate_relative_position()
- textactions_rendertext_image in ./textrender.inc 
- Place the text defined in the action onto the current background
File
- ./utility.inc, line 253 
- Utility form, conversion and rendering functions for image processes
Code
function imagecache_actions_calculate_relative_position($base, $layer, $style) {
  // $textimage should now have its size info available.
  // Calc the position
  if (isset($style['top'])) {
    $ypos = $style['top'];
  }
  if (isset($style['bottom'])) {
    $ypos = $base->info['height'] - ($layer->info['height'] + $style['bottom']);
  }
  if (!isset($ypos)) {
    // assume center
    $ypos = $base->info['height'] / 2 - $layer->info['height'] / 2;
  }
  if (isset($style['left'])) {
    $xpos = $style['left'];
  }
  if (isset($style['right'])) {
    $xpos = $base->info['width'] - ($layer->info['width'] + $style['right']);
  }
  if (!isset($xpos)) {
    // assume center
    $xpos = $base->info['width'] / 2 - $layer->info['width'] / 2;
  }
  return array(
    'x' => $xpos,
    'y' => $ypos,
  );
}