Home > Backend Development > PHP Tutorial > css - PHP: Is there any way to tell if a color value is close to white?

css - PHP: Is there any way to tell if a color value is close to white?

WBOY
Release: 2016-08-04 09:19:43
Original
1808 people have browsed it

Requirements:
Because if the background of some white text is close to white, the text will be unclear, so the text color needs to be set to black for this type of background color.


Known invalid methods:

Converting the color to decimal cannot determine whether it is close to white

<code>红色的值虽然是16711680 但和白色可以很好的区分.
但是灰色 12632256 比红色要小,但是和白色是很难区分的.</code>
Copy after login
Copy after login

Reply content:

Requirements:
Because if the background of some white text is close to white, the text will be unclear, so the text color needs to be set to black for this type of background color.


Known invalid methods:

Converting the color to decimal cannot determine whether it is close to white

<code>红色的值虽然是16711680 但和白色可以很好的区分.
但是灰色 12632256 比红色要小,但是和白色是很难区分的.</code>
Copy after login
Copy after login

Inverted. The smaller, the brighter

Just use the RGB value to judge. Find an unclear font and choose a color. If it meets the requirements and is greater than the RGB value, it must be unclear. You can also add an average value to judge.

Convert each digit of rgb to decimal and compare it with 255. For example, if the difference between each value and 255 is within 5, then it is considered to be very close to white, and you cannot directly convert the entire hexadecimal to decimal.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template