You are here

public function Generator::image in Style Guide 8

Same name and namespace in other branches
  1. 2.x src/Generator.php \Drupal\styleguide\Generator::image()

Generate a default image for display.

Parameters

string $image: The name of the image. Will be prefixed with 'styleguide-image-'.

string $type: The file type, (jpg, png, gif). Do not include a dot.

Return value

string The Drupal path to the file.

Overrides GeneratorInterface::image

File

src/Generator.php, line 164

Class

Generator
Class Generator.

Namespace

Drupal\styleguide

Code

public function image($image = 'vertical', $type = 'jpg', $min_resolution = '240x320', $max_resolution = '240x320') {
  $file_path = $this->config
    ->get('system.file')
    ->get('default_scheme') . '://styleguide-image-' . $image . '.' . $type;
  if ($image == 'horizontal') {
    $min_resolution = $max_resolution = '320x240';
  }
  $file_path = $this->random
    ->image($file_path, $min_resolution, $max_resolution);
  return file_exists($file_path) ? $file_path : NULL;
}