You are here

protected function ImagecacheProportionsFormatter::calculateImageStyle in Imagecache Proportions 8

Decides which image style should be displayed depending on the image size.

Parameters

string $image_uri: The URI to the image is going to be displayed.

Return value

string The name of the image style to display.

1 call to ImagecacheProportionsFormatter::calculateImageStyle()
ImagecacheProportionsFormatter::viewElements in src/Plugin/Field/FieldFormatter/ImagecacheProportionsFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/ImagecacheProportionsFormatter.php, line 179
Contains \Drupal\imagecache_proportions\Plugin\Field\FieldFormatter.

Class

ImagecacheProportionsFormatter
Plugin implementation of the 'imagecache_proportions' formatter.

Namespace

Drupal\imagecache_proportions\Plugin\Field\FieldFormatter

Code

protected function calculateImageStyle($image_uri) {
  $size = getimagesize($image_uri);
  if (abs($size[0] - $size[1]) <= $this
    ->getSetting('looseness')) {
    return 'image_style';
  }
  elseif ($size[0] > $size[1]) {
    return 'image_style_landscape';
  }
  else {
    return 'image_style_portrait';
  }
}