/** * @param array $data */ protected function generateTextColor(array &$data) { $dark = '#000000'; $bright = '#FAFAFA'; if (!isset($data['color'])) { $data['textColor'] = $dark; return; } $color = ColorUtility::getHEX($data['color']); if (!$color) { return; } $color = substr($color, 1); $red = hexdec(substr($color, 0, 2)); $green = hexdec(substr($color, 2, 2)); $blue = hexdec(substr($color, 4, 2)); $brightness = ($red * 299 + $green * 587 + $blue * 114) / 1000; $data['textColor'] = $brightness > 130 ? $dark : $bright; }
/** * @param string $color * @return $this */ public function setColor($color) { if (ColorUtility::isValid($color)) { $rgba = ColorUtility::getRGBA($color); return $this->setter('color', [$rgba]); } else { return $this; } }