Same name and namespace in other branches
  1. 7.x modules/image/image.module \image_filter_keyword()
  2. 8.9.x core/modules/image/image.module \image_filter_keyword()
  3. 9 core/modules/image/image.module \image_filter_keyword()

Returns the offset in pixels from the anchor.

Parameters

string $anchor: The anchor ('top', 'left', 'bottom', 'right', 'center').

int $current_size: The current size, in pixels.

int $new_size: The new size, in pixels.

Return value

int|string The offset from the anchor, in pixels, or the anchor itself, if its value isn't one of the accepted values.

File

core/modules/image/image.module, line 340
Exposes global functionality for creating image styles.

Code

function image_filter_keyword($anchor, $current_size, $new_size) {
  switch ($anchor) {
    case 'top':
    case 'left':
      return 0;
    case 'bottom':
    case 'right':
      return $current_size - $new_size;
    case 'center':
      return $current_size / 2 - $new_size / 2;
    default:
      return $anchor;
  }
}