You are here

public function ViewsPdfBase::convertHexColorToArray in Views PDF 8

Converts a hex color into an array with RGB colors.

1 call to ViewsPdfBase::convertHexColorToArray()
ViewsPdfBase::parseColor in src/ViewsPdfBase.php
Parse color input into an array.

File

src/ViewsPdfBase.php, line 274
Contains \Drupal\views_pdf\ViewsPdfTemplate.

Class

ViewsPdfBase
The main class to generate the PDF.

Namespace

Drupal\views_pdf

Code

public function convertHexColorToArray($hex) {
  if (drupal_strlen($hex) == 6) {
    $r = drupal_substr($hex, 0, 2);
    $g = drupal_substr($hex, 2, 2);
    $b = drupal_substr($hex, 4, 2);
    return [
      hexdec($r),
      hexdec($g),
      hexdec($b),
    ];
  }
  elseif (drupal_strlen($hex) == 3) {
    $r = drupal_substr($hex, 0, 1);
    $g = drupal_substr($hex, 1, 1);
    $b = drupal_substr($hex, 2, 1);
    return [
      hexdec($r),
      hexdec($g),
      hexdec($b),
    ];
  }
  else {
    return [];
  }
}