-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorFunctions.php
205 lines (180 loc) · 6.02 KB
/
ColorFunctions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
namespace Emotality\LaravelColor\Interfaces;
interface ColorFunctions
{
/**
* Get the hex color code with hashtag.
*
* @return string
*/
public function hex(): string;
/**
* Get the hex color code with hashtag.
*
* @return string
*/
public function hex8(): string;
/**
* Get red, green and blue from parsed color.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @return object
*/
public function rgb(string $hex = null): object;
/**
* Get hex code from red, green and blue.
*
* @param int $red
* @param int $green
* @param int $blue
* @return string
*/
public function rgbToHex(int $red, int $green, int $blue): string;
/**
* Get red, green, blue and alpha from parsed color.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @return object
*/
public function rgba(string $hex = null): object;
/**
* Get hex8 code from red, green, blue and alpha.
*
* @param int $red
* @param int $green
* @param int $blue
* @param float $alpha
* @return string
*/
public function rgbaToHex8(int $red, int $green, int $blue, float $alpha = 1): string;
/**
* Get hue, saturation and lightness from parsed color.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @return object
* @url https://www.had2know.org/technology/hsl-rgb-color-converter.html
* @url https://www.rapidtables.com/convert/color/rgb-to-hsl.html
* @url https://bgrins.github.io/TinyColor/
*/
public function hsl(string $hex = null): object;
/**
* Get hue, saturation and value from parsed color.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @return object
* @url https://www.had2know.org/technology/hsv-rgb-conversion-formula-calculator.html
* @url https://www.rapidtables.com/convert/color/rgb-to-hsv.html
* @url https://bgrins.github.io/TinyColor/
*/
public function hsv(string $hex = null): object;
/**
* Get the hue from parsed color in a value out of 360.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @return int
*/
public function hue(string $hex = null): int;
/**
* Get the value from parsed color in a percentage value.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @return int
*/
public function value(string $hex = null): int;
/**
* Color relative luminance from parsed color in a percentage value.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @return float
*/
public function luminance(string $hex = null): float;
/**
* Get the lightness from parsed color in a percentage value.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @return int
*/
public function lightness(string $hex = null): int;
/**
* Get the brightness from parsed color in a percentage value.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @return int
*/
public function brightness(string $hex = null): int;
/**
* If the parsed color is darker than specified contrast percentage.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @param int|null $contrast The percentage of contrast to measure against, default is 50.
* @return bool
*/
public function isDark(string $hex = null, int $contrast = null): bool;
/**
* If the parsed color is lighter than specified contrast percentage.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @param int|null $contrast The percentage of contrast to measure against, default is 50.
* @return bool
*/
public function isLight(string $hex = null, int $contrast = null): bool;
/**
* Foreground font color if parsed color is the background.
*
* @param string|null $hex The hex color code to parse, with or without hashtag.
* @param int|null $contrast The percentage of contrast to measure against, default is 50.
* @return string
*/
public function fontColor(string $hex = null, int $contrast = null): string;
/**
* @param string $color1_hex
* @param string $color2_hex
* @param int $percentage
* @return string
* @throws \Emotality\LaravelColor\LaravelColorException
*/
public function mix(string $color1_hex, string $color2_hex, int $percentage = 50): string;
/**
* @param int $percentage
* @param string|null $hex
* @return string
*/
public function tint(int $percentage = 10, string $hex = null): string;
/**
* @param int $count
* @param string|null $hex
* @return array
*/
public function getTints(int $count = 20, string $hex = null): array;
/**
* @param int $percentage
* @param string|null $hex
* @return string
*/
public function shade(int $percentage = 10, string $hex = null): string;
/**
* @param int $count
* @param string|null $hex
* @return array
*/
public function getShades(int $count = 20, string $hex = null): array;
/**
* Return all info about the parsed color in a JSON string format.
*
* @param int $flags json_decode() flags.
* @return string
*/
public function toJson(int $flags = 0): string;
/**
* Return all info about the parsed color in an array format.
*
* @return array<string, mixed>
*/
public function toArray(): array;
/**
* Return all info about the parsed color in an object format.
*
* @return object
*/
public function toObject(): object;
}