You are here

public function ImageWidgetCropManager::imageStylesOperations in Image Widget Crop 8

Same name and namespace in other branches
  1. 8.2 src/ImageWidgetCropManager.php \Drupal\image_widget_crop\ImageWidgetCropManager::imageStylesOperations()

Apply different operation on ImageStyles.

Parameters

array $image_styles: All ImageStyles used by this cropType.

string $file_uri: Uri of image uploaded by user.

bool $create_derivative: Boolean to create an derivative of the image uploaded.

1 call to ImageWidgetCropManager::imageStylesOperations()
ImageWidgetCropManager::deleteCrop in src/ImageWidgetCropManager.php
Delete the crop when user delete it.

File

src/ImageWidgetCropManager.php, line 305

Class

ImageWidgetCropManager
ImageWidgetCropManager calculation class.

Namespace

Drupal\image_widget_crop

Code

public function imageStylesOperations(array $image_styles, $file_uri, $create_derivative = FALSE) {

  /** @var \Drupal\image\Entity\ImageStyle $image_style */
  foreach ($image_styles as $image_style) {
    if ($create_derivative) {

      // Generate the image derivative uri.
      $destination_uri = $image_style
        ->buildUri($file_uri);

      // Create a derivative of the original image with a good uri.
      $image_style
        ->createDerivative($file_uri, $destination_uri);
    }

    // Flush the cache of this ImageStyle.
    $image_style
      ->flush($file_uri);
  }
}