You are here

protected function BlazyManager::createPlaceholder in Blazy 7

Same name and namespace in other branches
  1. 8.2 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 313

Class

BlazyManager
Implements a public facing blazy manager.

Namespace

Drupal\blazy

Code

protected function createPlaceholder(array &$settings, $style = NULL, $path = '') {
  if (empty($path) && ($style = image_style_load('thumbnail')) && file_valid_uri($settings['uri'])) {
    $path = image_style_path('thumbnail', $settings['uri']);
  }
  if ($path && file_valid_uri($path)) {

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

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