You are here

function CollageFormatter::collageformatter_upscaling_check in Collage Formatter 8

Checks for upscaled images and returns the scaling factor.

Parameters

$box: array - array of images boxed as configured

  • @param $settings array - array containing settings/configurations
1 call to CollageFormatter::collageformatter_upscaling_check()
CollageFormatter::collageformatter_render_collage in src/Plugin/Field/FieldFormatter/CollageFormatter.php
Returns renderable array of collages.

File

src/Plugin/Field/FieldFormatter/CollageFormatter.php, line 781
Contains \Drupal\collageformatter\src\Plugin\Field\FieldFormatter\CollageFormatter.

Class

CollageFormatter
Plugin implementation of the 'collageformatter' formatter.

Namespace

Drupal\collageformatter\Plugin\Field\FieldFormatter

Code

function collageformatter_upscaling_check($box, $settings) {
  $scale1 = $scale2 = 1;
  if ($box['box_type'] == 'box') {
    $scale1 = $this
      ->collageformatter_upscaling_check($box[1], $settings);
    $scale2 = $this
      ->collageformatter_upscaling_check($box[2], $settings);
  }
  elseif ($box['box_type'] == 'image') {
    $width = $box['total_width'] - 2 * $settings['border_size'] - $settings['gap_size'];
    $height = $box['total_height'] - 2 * $settings['border_size'] - $settings['gap_size'];
    if ($box['width'] < $width) {
      $scale1 = $box['width'] / $width;
    }
    if ($box['height'] < $height) {
      $scale1 = $box['height'] / $height;
    }
  }
  return $scale1 <= $scale2 ? $scale1 : $scale2;
}