Answer the question
In order to leave comments, you need to log in
How to write a condition where the parameter is a color?
Greetings!
I'm looking for a way to write a condition where the parameter is a color in any format, if it would work.
Now I do this:
if ($page_back_color > '#f2f2f1') {
голова
} else {
ноги
}
Answer the question
In order to leave comments, you need to log in
Color is usually characterized by three parameters. Depending on the color model: RGB (red, green, blue); HSV (hue, saturation, lightness); Lab (brightness, red-green axis, blue-yellow axis), etc. More-less can only be compared along one axis.
"darker than #f2f2f1" - can be determined by converting the color from RGB to HSV or Lab (google formulas) and comparing only the brightness component.
Well, or ugly to simplify to three comparisons: each of the R, G, B components: R < 0xF2 || B < 0xF2 || B < 0xF1
Here the jamb is that one component (for example, R) is slightly less than the threshold, and the rest are much higher than it - they will give a lighter color, and this approach consider it darker.
str_split('f1f2f3', 2) will give an array of ['f1', 'f2', 'f3']
.
intval('f1', 16) will make the number 241 from the string 'f1'.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question