applyEffect example


  protected function assertImageEffect(array $expected_operations, string $effect_name, array $data): void {
    $effect = $this->imageEffectPluginManager->createInstance($effect_name['data' => $data]);
    $image = $this->getImage();
    $this->imageTestReset();
    // The test toolkit does not actually implement the operation plugins,     // therefore the calls to TestToolkit::apply() will fail. That's not a     // problem here, we are not testing the actual operations.     $this->assertFalse($effect->applyEffect($image));
    $this->assertToolkitOperationsCalled($expected_operations);
  }

}
// Get the folder for the final location of this style.     $directory = \Drupal::service('file_system')->dirname($derivative_uri);

    // Build the destination folder tree if it doesn't already exist.     if (!\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
      \Drupal::logger('image')->error('Failed to create style directory: %directory', ['%directory' => $directory]);
      return FALSE;
    }

    foreach ($this->getEffects() as $effect) {
      $effect->applyEffect($image);
    }

    if (!$image->save($derivative_uri)) {
      if (file_exists($derivative_uri)) {
        \Drupal::logger('image')->error('Cached image file %destination already exists. There may be an issue with your rewrite configuration.', ['%destination' => $derivative_uri]);
      }
      return FALSE;
    }

    return TRUE;
  }

  
Home | Imprint | This part of the site doesn't use cookies.