function imagefield_focus_parse in ImageField Focus 7
Same name and namespace in other branches
- 6 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_effect in ./
imagefield_focus.effects.inc - imagefield_focus_scale_and_crop_effect in ./
imagefield_focus.effects.inc - imagefield_focus_widget_validate in ./
imagefield_focus.module - Element #element_validate callback function.
File
- ./
imagefield_focus.module, line 332
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'];
$rect['anchor'] = $rect['x'] . '-' . $rect['y'];
return $rect;
}