You are here

public function BackgroundImageManager::colorIsDark in Background Image 8

Same name and namespace in other branches
  1. 2.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::colorIsDark()
  2. 2.0.x src/BackgroundImageManager.php \Drupal\background_image\BackgroundImageManager::colorIsDark()

Determines if a color is "dark".

Parameters

string $hex: A HEX color representation.

Return value

bool TRUE or FALSE

Overrides BackgroundImageManagerInterface::colorIsDark

File

src/BackgroundImageManager.php, line 222

Class

BackgroundImageManager

Namespace

Drupal\background_image

Code

public function colorIsDark($hex = NULL) {
  if (!isset($hex)) {
    return FALSE;
  }
  $rgb = array_values(Color::hexToRgb($hex));
  return 0.213 * $rgb[0] + 0.715 * $rgb[1] + 0.07199999999999999 * $rgb[2] < 255 / 2;
}