You are here

function imagefield_focus_parse in ImageField Focus 6

Same name and namespace in other branches
  1. 7 imagefield_focus.module \imagefield_focus_parse()

Parse a rectangle from a given string.

Return value

A rectangle array or FALSE.

3 calls to imagefield_focus_parse()
imagefield_focus_crop_image in ./imagefield_focus_imagecache_actions.inc
imagefield_focus_scale_and_crop_image in ./imagefield_focus_imagecache_actions.inc
imagefield_focus_widget_validate in ./imagefield_focus.module
Element #element_validate callback function.

File

./imagefield_focus.module, line 316
Written by Henri MEDOT <henri.medot[AT]absyx[DOT]fr> http://www.absyx.fr

Code

function imagefield_focus_parse($rect) {
  $values = explode(',', $rect);
  if (count($values) != 4) {
    return FALSE;
  }
  $keys = array(
    'x',
    'y',
    'width',
    'height',
  );
  $rect = array();
  for ($i = 0; $i < 4; $i++) {
    $value = $values[$i];
    if (!is_numeric($value)) {
      return FALSE;
    }
    $rect[$keys[$i]] = round($value);
  }
  if ($rect['x'] < 0 || $rect['y'] < 0 || $rect['width'] <= 0 || $rect['height'] <= 0) {
    return FALSE;
  }
  $rect['xoffset'] = $rect['x'];
  $rect['yoffset'] = $rect['y'];
  return $rect;
}