function image_filter_keyword

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

Accepts a keyword (center, top, left, etc) and returns it as a pixel offset.

Parameters

$value:

$current_pixels:

$new_pixels:

2 calls to image_filter_keyword()
CropImageEffect::applyEffect in core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php
Applies an image effect to the image object.
ScaleAndCropImageEffect::applyEffect in core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php
Applies an image effect to the image object.

File

core/modules/image/image.module, line 351

Code

function image_filter_keyword($value, $current_pixels, $new_pixels) {
  switch ($value) {
    case 'top':
    case 'left':
      return 0;
    case 'bottom':
    case 'right':
      return $current_pixels - $new_pixels;
    case 'center':
      return $current_pixels / 2 - $new_pixels / 2;
  }
  return $value;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.