function imagecache_actions_keyword_filter in ImageCache Actions 6
Same name and namespace in other branches
- 8 utility.inc \imagecache_actions_keyword_filter()
- 6.2 utility.inc \imagecache_actions_keyword_filter()
- 7 utility.inc \imagecache_actions_keyword_filter()
Accept a keyword (center, top, left, etc) and return it as an offset in pixels. Called on either the x or y values.
May be something like "20", "center", "left+20", "bottom+10". + values are in from the sides, so bottom+10 is 10 UP from the bottom.
"center+50" is also OK.
"30%" will place the CENTER of the object at 30% across. to get a 30% margin, use "left+30%"
Parameters
$value : string or int value.
$current_size: int size in pixels of the range this item is to be placed in
$object_size: int size in pixels of the object to be placed
1 call to imagecache_actions_keyword_filter()
- imageapi_image_overlay in ./
imagecache_canvasactions.module - Place one image over another
File
- ./
utility.inc, line 182 - Utility form, conversion and rendering functions for image processes
Code
function imagecache_actions_keyword_filter($value, $current_size, $object_size) {
$keyword = '';
$offset = 0;
// Check if we have plus or minus values
// Assume that no + means a raw value
$keyword_split = explode('+', $value);
$keyword = $keyword_split[0];
if (!empty($keyword_split[1])) {
$offset = intval($keyword_split[1]);
}
if (strstr($value, '-')) {
$keyword_split = explode('-', $value);
$keyword = $keyword_split[0];
if (!empty($keyword_split[1])) {
$offset = -1 * intval($keyword_split[1]);
}
}
// handle % values
if (substr($value, strlen($value) - 1, 1) == '%') {
$percent = TRUE;
$offset = intval($offset);
$value = intval($value / 100 * $current_size);
if (!$keyword) {
// just said eg '25%' - so center the object there
$offset = $object_size / -2;
}
else {
// Otherwise the keyword will give us the new value, and the % will be its offset
$offset = intval($offset / 100 * $current_size);
}
}
#dpm(get_defined_vars());
// Whether the value is 'top or left doesn't matter, treat both axes the same.
switch ($keyword) {
case 'top':
case 'left':
$value = 0;
break;
case 'bottom':
case 'right':
$value = $current_size - $object_size;
$offset = -1 * $offset;
break;
case 'center':
case 'middle':
$value = $current_size / 2 - $object_size / 2;
break;
default:
// if no keyword, it was a raw number - assume top left then
$value = intval($value);
}
#dpm(get_defined_vars());
#dpm("Placing an object $object_size big on a range of $current_size at a position of $value , $offset");
// Add any extra negative or positive
if (!empty($offset)) {
$value = $value + $offset;
}
return $value;
}