Advertisement
SoWesley

PHP Function Html2RGB

May 22nd, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. /* Function to convert HTML colors to Array with RGB info.
  2.  
  3.    Example of usage with TCPDF for PDF reporting:
  4.  
  5.    $Backcolor = $this->html2rgb('#FFF8F0');
  6.    $this->SetFillColor($Backcolor[2], $Backcolor[1], $Backcolor[0]);
  7.  
  8. */
  9.  
  10. function html2rgb($color)
  11.     {
  12.         if ($color[0] == '#')
  13.             $color = substr($color, 1);
  14.    
  15.         if (strlen($color) == 6)
  16.             list($r, $g, $b) = array($color[0].$color[1],
  17.                                      $color[2].$color[3],
  18.                                      $color[4].$color[5]);
  19.         elseif (strlen($color) == 3)
  20.             list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
  21.         else
  22.             return false;
  23.    
  24.         $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
  25.    
  26.         return array($r, $g, $b);
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement