You are here

public static function ColorUtility::opacityToAlpha in Image Effects 8.3

Same name and namespace in other branches
  1. 8 src/Component/ColorUtility.php \Drupal\image_effects\Component\ColorUtility::opacityToAlpha()
  2. 8.2 src/Component/ColorUtility.php \Drupal\image_effects\Component\ColorUtility::opacityToAlpha()

Convert percent opacity to hex alpha.

Parameters

int $value: Opacity as percentage (0 = transparent, 100 = fully opaque).

Return value

string|null Opacity as HEX (#00 = transparent, #FF = fully opaque).

1 call to ColorUtility::opacityToAlpha()
ImageEffectsColor::valueCallback in src/Element/ImageEffectsColor.php
Determines how user input is mapped to an element's #value property.

File

src/Component/ColorUtility.php, line 58

Class

ColorUtility
Color handling methods for image_effects.

Namespace

Drupal\image_effects\Component

Code

public static function opacityToAlpha($value) {
  if (!$value || $value < 0 || $value > 100) {
    return NULL;
  }
  return mb_strtoupper(str_pad(dechex(ceil($value / 100 * 255)), 2, '0', STR_PAD_LEFT));
}