You are here

public function CarouselService::renderImageById in bootstrap simple carousel 8

Return a rendered image.

Parameters

int $image_id: The image id for the carousel.

string $image_style: The image style for the carousel.

array $params: An array of parameters.

Return value

string Rendered image

Throws

\Exception

File

src/Service/CarouselService.php, line 62

Class

CarouselService
CarouselService Class.

Namespace

Drupal\bootstrap_simple_carousel\Service

Code

public function renderImageById($image_id, $image_style = 'thumbnail', array $params = []) {
  $image = '';
  $imageFile = $this->file
    ->load($image_id);
  if (!empty($imageFile)) {
    $imageTheme = [
      '#theme' => 'image_style',
      '#style_name' => $image_style,
      '#uri' => $imageFile
        ->getFileUri(),
      '#alt' => $params['alt'] ?? '',
      '#title' => $params['title'] ?? '',
    ];
    $image = $this->renderer
      ->render($imageTheme);
  }
  return $image;
}