You are here

public function ImageStyleFlushTest::createSampleImage in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/image/tests/src/Functional/ImageStyleFlushTest.php \Drupal\Tests\image\Functional\ImageStyleFlushTest::createSampleImage()
  2. 9 core/modules/image/tests/src/Functional/ImageStyleFlushTest.php \Drupal\Tests\image\Functional\ImageStyleFlushTest::createSampleImage()

Given an image style and a wrapper, generate an image.

File

core/modules/image/tests/src/Functional/ImageStyleFlushTest.php, line 29

Class

ImageStyleFlushTest
Tests flushing of image styles.

Namespace

Drupal\Tests\image\Functional

Code

public function createSampleImage($style, $wrapper) {
  static $file;
  if (!isset($file)) {
    $files = $this
      ->drupalGetTestFiles('image');
    $file = reset($files);
  }

  // Make sure we have an image in our wrapper testing file directory.
  $source_uri = \Drupal::service('file_system')
    ->copy($file->uri, $wrapper . '://');

  // Build the derivative image.
  $derivative_uri = $style
    ->buildUri($source_uri);
  $derivative = $style
    ->createDerivative($source_uri, $derivative_uri);
  return $derivative ? $derivative_uri : FALSE;
}