You are here

protected function BlazyManager::createPlaceholder in Blazy 8.2

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

Build thumbnails, also to provide placeholder for blur effect.

1 call to BlazyManager::createPlaceholder()
BlazyManager::thumbnailAndPlaceholder in src/BlazyManager.php
Build thumbnails, also to provide placeholder for blur effect.

File

src/BlazyManager.php, line 413

Class

BlazyManager
Implements a public facing blazy manager.

Namespace

Drupal\blazy

Code

protected function createPlaceholder(array &$settings, $style = NULL, $path = '') {
  if (empty($path) && ($style = $this
    ->entityLoad('thumbnail', 'image_style')) && BlazyUtil::isValidUri($settings['uri'])) {
    $path = $style
      ->buildUri($settings['uri']);
  }
  if ($path && BlazyUtil::isValidUri($path)) {

    // Ensures the thumbnail exists before creating a dataURI.
    if (!is_file($path) && $style) {
      $style
        ->createDerivative($settings['uri'], $path);
    }

    // Overrides placeholder with data URI based on configured thumbnail.
    if (is_file($path)) {
      $settings['placeholder_fx'] = 'data:image/' . pathinfo($path, PATHINFO_EXTENSION) . ';base64,' . base64_encode(file_get_contents($path));

      // Prevents double animations.
      $settings['use_loading'] = FALSE;
    }
  }
}