You are here

public static function BlazyUtil::transformDimensions in Blazy 8.2

A wrapper for ImageStyle::transformDimensions().

Parameters

object $style: The given image style.

array $data: The data settings: _width, _height, _uri, width, height, and uri.

bool $initial: Whether particularly transforms once for all, or individually.

5 calls to BlazyUtil::transformDimensions()
BlazyFormatter::setImageDimensions in src/BlazyFormatter.php
Sets dimensions once to reduce method calls, if image style contains crop.
BlazyLightbox::build in src/BlazyLightbox.php
Gets media switch elements: all lightboxes, not content, nor iframe.
BlazyManager::buildResponsiveImage in src/BlazyManager.php
Build out Responsive image.
BlazyManagerBase::setResponsiveImageDimensions in src/BlazyManagerBase.php
Sets dimensions once to reduce method calls for Responsive image.
BlazyUtil::imageUrl in src/BlazyUtil.php
Provides image url based on the given settings.

File

src/BlazyUtil.php, line 176

Class

BlazyUtil
Provides Blazy utilities.

Namespace

Drupal\blazy

Code

public static function transformDimensions($style, array $data, $initial = FALSE) {
  $uri = $initial ? '_uri' : 'uri';
  $key = hash('md2', $style
    ->id() . $data[$uri]);
  if (!isset(static::$styleId[$key])) {
    $width = $initial ? '_width' : 'width';
    $height = $initial ? '_height' : 'height';
    $width = isset($data[$width]) ? $data[$width] : NULL;
    $height = isset($data[$height]) ? $data[$height] : NULL;
    $dim = [
      'width' => $width,
      'height' => $height,
    ];

    // Funnily $uri is ignored at all core image effects.
    $style
      ->transformDimensions($dim, $data[$uri]);

    // Sometimes they are string, cast them integer to reduce JS logic.
    if ($dim['width'] != NULL) {
      $dim['width'] = (int) $dim['width'];
    }
    if ($dim['height'] != NULL) {
      $dim['height'] = (int) $dim['height'];
    }
    static::$styleId[$key] = [
      'width' => $dim['width'],
      'height' => $dim['height'],
    ];
  }
  return static::$styleId[$key];
}