You are here

public function MaxSizeCropImageEffect::applyEffect in Image max size crop 8

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 CropImageEffect::applyEffect

File

src/Plugin/ImageEffect/MaxSizeCropImageEffect.php, line 26

Class

MaxSizeCropImageEffect
Crop image with maximum sizes.

Namespace

Drupal\image_max_size_crop\Plugin\ImageEffect

Code

public function applyEffect(ImageInterface $image) {

  // Set the desired dimensions, if the width is empty or not high enough.
  $original_width = $this->configuration['width'];
  if (!$this->configuration['width'] || $this->configuration['width'] > $image
    ->getWidth()) {
    $this->configuration['width'] = $image
      ->getWidth();
  }

  // Set the desired dimensions, if the height is empty or not high enough.
  $original_height = $this->configuration['height'];
  if (!$this->configuration['height'] || $this->configuration['height'] > $image
    ->getHeight()) {
    $this->configuration['height'] = $image
      ->getHeight();
  }
  $result = parent::applyEffect($image);

  // Restore configuration so that settings screen is shown correctly.
  $this->configuration['width'] = $original_width;
  $this->configuration['height'] = $original_height;
  return $result;
}