You are here

public static function ImageUtility::percentFilter in Image Effects 8.2

Same name and namespace in other branches
  1. 8.3 src/Component/ImageUtility.php \Drupal\image_effects\Component\ImageUtility::percentFilter()
  2. 8 src/Component/ImageUtility.php \Drupal\image_effects\Component\ImageUtility::percentFilter()

Computes a length based on a length specification and an actual length.

Examples: (50, 400) returns 50; (50%, 400) returns 200; (50, null) returns 50; (50%, null) returns null; (null, null) returns null; (null, 100) returns null.

Parameters

string|null $length_specification: The length specification. An integer value or a % specification.

int|null $current_length: The current length. May be null.

Return value

int|null The computed length.

7 calls to ImageUtility::percentFilter()
ImagemagickArgumentsImageEffect::getDimensions in src/Plugin/ImageEffect/ImagemagickArgumentsImageEffect.php
Calculate resulting image dimensions.
ImageUtility::resizeDimensions in src/Component/ImageUtility.php
Determines the dimensions of a resized image.
ImageUtilityTest::testPercentFilter in tests/src/Unit/ImageUtilityTest.php
@covers ::percentFilter @dataProvider percentFilterProvider
MaskImageEffect::applyEffect in src/Plugin/ImageEffect/MaskImageEffect.php
Applies an image effect to the image object.
ScaleAndSmartCropImageEffect::transformDimensions in src/Plugin/ImageEffect/ScaleAndSmartCropImageEffect.php
Determines the dimensions of the styled image.

... See full list

File

src/Component/ImageUtility.php, line 26

Class

ImageUtility
Image handling methods for image_effects.

Namespace

Drupal\image_effects\Component

Code

public static function percentFilter($length_specification, $current_length) {
  if (strpos($length_specification, '%') !== FALSE) {
    $length_specification = $current_length !== NULL ? str_replace('%', '', $length_specification) * 0.01 * $current_length : NULL;
  }
  return is_null($length_specification) ? NULL : (int) $length_specification;
}