You are here

public static function SampleDataLoader::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: The extension to use for fetching the image.

Return value

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

1 call to SampleDataLoader::getImage()
SampleDataLoader::loadSample in modules/sample_data/src/SampleDataLoader.php
Load sample data based on type and additional parameters.

File

modules/sample_data/src/SampleDataLoader.php, line 172

Class

SampleDataLoader
Provides methods for retrieving sample data to be used in demo content.

Namespace

Drupal\sample_data

Code

public static 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);
}