You are here

public function PdfTemplate::convertHexColorToArray in Views PDF 6

Same name and namespace in other branches
  1. 7.3 views_pdf_template.php \PdfTemplate::convertHexColorToArray()
  2. 7 views_pdf_template.php \PdfTemplate::convertHexColorToArray()
  3. 7.2 views_pdf_template.php \PdfTemplate::convertHexColorToArray()

Converts a hex color into an array with RGB colors.

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

File

./views_pdf_template.php, line 163
PDF Class to generate PDFs with native PHP. This class based on FPDF and FPDI.

Class

PdfTemplate
The main class to generate the PDF.

Code

public function convertHexColorToArray($hex) {
  if (strlen($hex) == 6) {
    $r = substr($hex, 0, 2);
    $g = substr($hex, 2, 2);
    $b = substr($hex, 4, 2);
    return array(
      hexdec($r),
      hexdec($g),
      hexdec($b),
    );
  }
  elseif (strlen($hex) == 3) {
    $r = substr($hex, 0, 1);
    $g = substr($hex, 1, 1);
    $b = substr($hex, 2, 1);
    return array(
      hexdec($r),
      hexdec($g),
      hexdec($b),
    );
  }
  else {
    return array();
  }
}