| @@ 23-30 (lines=8) @@ | ||
| 20 | * @param string $hex The hex string to convert (no #) |
|
| 21 | * @return array The RGB array |
|
| 22 | */ |
|
| 23 | public static function hex_to_rgb(string $hex = '000000') :array { |
|
| 24 | regulate::hex($hex); |
|
| 25 | return [ |
|
| 26 | 'r' => hexdec(substr($hex, 0, 2)), |
|
| 27 | 'g' => hexdec(substr($hex, 2, 2)), |
|
| 28 | 'b' => hexdec(substr($hex, 4, 2)) |
|
| 29 | ]; |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Convert a RBA array to a hex string |
|
| @@ 10-17 (lines=8) @@ | ||
| 7 | ||
| 8 | protected static $default_value = '000000'; |
|
| 9 | ||
| 10 | public static function to_rgb($input) :array { |
|
| 11 | $hex = static::_validate_hex_input($input); |
|
| 12 | return [ |
|
| 13 | 'r' => hexdec(substr($hex, 0, 2)), |
|
| 14 | 'g' => hexdec(substr($hex, 2, 2)), |
|
| 15 | 'b' => hexdec(substr($hex, 4, 2)) |
|
| 16 | ]; |
|
| 17 | } |
|
| 18 | ||
| 19 | public static function to_hex($input) :string { |
|
| 20 | return static::_validate_hex_input($input); |
|