You are here

protected function BlazyManager::thumbnailAndPlaceholder in Blazy 7

Same name and namespace in other branches
  1. 8.2 src/BlazyManager.php \Drupal\blazy\BlazyManager::thumbnailAndPlaceholder()

Build thumbnails, also to provide placeholder for blur effect.

1 call to BlazyManager::thumbnailAndPlaceholder()
BlazyManager::prepareImage in src/BlazyManager.php
Prepares the Blazy image as a structured array ready for ::renderer().

File

src/BlazyManager.php, line 283

Class

BlazyManager
Implements a public facing blazy manager.

Namespace

Drupal\blazy

Code

protected function thumbnailAndPlaceholder(array &$attributes, array &$settings) {
  $path = $style = '';

  // With CSS background, IMG may be empty, add thumbnail to the container.
  if (!empty($settings['thumbnail_style'])) {
    $path = image_style_path($settings['thumbnail_style'], $settings['uri']);
    $style = image_style_load($settings['thumbnail_style']);
    $attributes['data-thumb'] = image_style_url($settings['thumbnail_style'], $settings['uri']);
  }

  // Supports unique thumbnail different from main image, such as logo for
  // thumbnail and main image for company profile.
  if (!empty($settings['thumbnail_uri'])) {
    $path = $settings['thumbnail_uri'];
    $attributes['data-thumb'] = file_create_url($path);
  }
  if (isset($style) && ($path && !is_file($path) && file_valid_uri($path))) {
    image_style_create_derivative($style, $settings['uri'], $path);
  }

  // Provides image effect if so configured.
  if (!empty($settings['fx'])) {
    $this
      ->createPlaceholder($settings, $style, $path);
    $attributes['class'][] = 'media--fx--' . str_replace('_', '-', $settings['fx']);
  }
}