Exemplo n.º 1
0
 /**
  * @param  string $hex
  *
  * @return array
  */
 function hex_to_rgb($hex)
 {
     if (!validate_hex_color($hex)) {
         return null;
     }
     $hex = str_replace("#", "", $hex);
     if (strlen($hex) == 3) {
         $red = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));
         $green = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1));
         $blue = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1));
     } else {
         $red = hexdec(substr($hex, 0, 2));
         $green = hexdec(substr($hex, 2, 2));
         $blue = hexdec(substr($hex, 4, 2));
     }
     return [$red, $green, $blue];
 }
Exemplo n.º 2
0
 /**
  * Check if HEX is valid
  *
  * @param string $hex
  *
  * @return bool
  */
 private function isHexValid($hex)
 {
     return validate_hex_color($hex);
 }