You are here

protected function CaptchaImageResponse::hexToRgb in CAPTCHA 8

Small helper function for parsing a hexadecimal color to a RGB tuple.

Parameters

string $hex: String representation of HEX color value.

Return value

array Array representation of RGB color value.

1 call to CaptchaImageResponse::hexToRgb()
CaptchaImageResponse::printString in image_captcha/src/Response/CaptchaImageResponse.php
Helper function for drawing text on the image.

File

image_captcha/src/Response/CaptchaImageResponse.php, line 137

Class

CaptchaImageResponse
Response which is returned as the captcha for image_captcha.

Namespace

Drupal\image_captcha\Response

Code

protected function hexToRgb($hex) {
  if (strlen($hex) == 4) {
    $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];
  }
  $c = hexdec($hex);
  $rgb = [];
  for ($i = 16; $i >= 0; $i -= 8) {
    $rgb[] = $c >> $i & 0xff;
  }
  return $rgb;
}