You are here

public function AspectSwitcherImageEffect::applyEffect in Image Effects 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageEffect/AspectSwitcherImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\AspectSwitcherImageEffect::applyEffect()
  2. 8.2 src/Plugin/ImageEffect/AspectSwitcherImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\AspectSwitcherImageEffect::applyEffect()

Applies an image effect to the image object.

Parameters

\Drupal\Core\Image\ImageInterface $image: An image file object.

Return value

bool TRUE on success. FALSE if unable to perform the image effect on the image.

Overrides ImageEffectInterface::applyEffect

File

src/Plugin/ImageEffect/AspectSwitcherImageEffect.php, line 145

Class

AspectSwitcherImageEffect
Choose image styles to apply based on source image orientation.

Namespace

Drupal\image_effects\Plugin\ImageEffect

Code

public function applyEffect(ImageInterface $image) {
  $style_name = $this
    ->getChildImageStyleToExecute($image
    ->getWidth(), $image
    ->getHeight());
  $style = $this
    ->failSafeGetImageStyle($style_name);

  // No child style to process.
  if ($style === NULL) {
    return TRUE;
  }

  // Child style to process missing.
  if ($style === FALSE) {
    return FALSE;
  }
  foreach ($style
    ->getEffects() as $effect) {
    $effect
      ->applyEffect($image);
  }
  return TRUE;
}