You are here

public function ImageGenerator::getImage in YAML Content 8.2

Helper function to fetch images.

Parameters

string $width: The width of the image to fetch.

string $height: The height of the image to fetch.

string $ext: (Optional) The extension to use for fetching the image.

Return value

\Drupal\file\FileInterface|false The file entity that was created.

1 call to ImageGenerator::getImage()
ImageGenerator::execute in modules/sample_data/src/Plugin/SampleData/ImageGenerator.php
A uniform execution function for all plugins to implement.

File

modules/sample_data/src/Plugin/SampleData/ImageGenerator.php, line 40

Class

ImageGenerator
Sample data generator to provide basic placeholder images.

Namespace

Drupal\sample_data\Plugin\SampleData

Code

public function getImage($width, $height, $ext = "png") {
  $image = file_get_contents("http://placehold.it/{$width}" . 'x' . $height);
  return file_save_data($image, "public://{$width}" . 'x' . "{$height}.{$ext}", FILE_EXISTS_REPLACE);
}