1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace projectcleverweb\color; |
5
|
|
|
|
6
|
|
|
class regulate { |
7
|
|
|
|
8
|
|
|
public static function percent(float &$value) { |
9
|
|
|
$value = abs($value) % 101; |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
public static function rgb(int &$value) { |
13
|
|
|
$value = abs($value) % 256; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public static function rgb_array(array &$rgb_array) { |
17
|
|
|
static::rgb($rgb_array['r']); |
18
|
|
|
static::rgb($rgb_array['g']); |
19
|
|
|
static::rgb($rgb_array['b']); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public static function hsl(float &$value, string $offset) { |
23
|
|
|
if (strtolower($offset) == 'h') { |
24
|
|
|
$value = abs($value) % 360; |
25
|
|
|
} |
26
|
|
|
static::percent($value); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public static function hsl_array(array &$hsl_array) { |
30
|
|
|
static::hsl($hsl_array['h'], 'h'); |
31
|
|
|
static::hsl($hsl_array['s'], 's'); |
32
|
|
|
static::hsl($hsl_array['l'], 'l'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public static function cmyk(float &$value) { |
36
|
|
|
static::percent($value); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public static function cmyk_array(array &$cmyk_array) { |
40
|
|
|
static::cmyk($cmyk_array['c']); |
41
|
|
|
static::cmyk($cmyk_array['m']); |
42
|
|
|
static::cmyk($cmyk_array['y']); |
43
|
|
|
static::cmyk($cmyk_array['k']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function hex(string &$str) { |
|
|
|
|
47
|
|
|
static::_validate_hex_str($color); |
48
|
|
|
static::_strip_hash($color); |
49
|
|
|
static::_expand_shorthand($color); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function hex_int(int &$value) { |
53
|
|
|
$value = abs($value) % 0x1FFFFFF; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
protected static function _strip_hash(&$hex) { |
58
|
|
|
if (is_string($hex) && substr($hex, 0 ,1) == '#') { |
59
|
|
|
$hex = substr($hex, 1); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected static function _expand_shorthand(string &$hex_str) { |
64
|
|
|
if (strlen($hex) === 3) { |
65
|
|
|
$r = $hex[0]; |
|
|
|
|
66
|
|
|
$g = $hex[1]; |
|
|
|
|
67
|
|
|
$b = $hex[2]; |
|
|
|
|
68
|
|
|
$hex_str = $r.$r.$g.$g.$b.$b; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected static function _validate_hex_str(&$hex_str) { |
73
|
|
|
if (is_string($hex_str) && preg_match('/\A#?(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})\Z/i', $hex_str)) { |
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
// Error - Force color and trigger notice |
77
|
|
|
$hex_str = '000000'; |
78
|
|
|
// [todo] Trigger Error |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.