change font color if background is dark or light in php
get_brightness($hex) {
// returns brightness value from 0 to 255
// strip off any leading #
$hex = str_replace('#', '', $hex);
$c_r = hexdec(substr($hex, 0, 2));
$c_g = hexdec(substr($hex, 2, 2));
$c_b = hexdec(substr($hex, 4, 2));
return (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
}
$color = "#******";
if ($get_brightness($color) > 130) { // will have to experiment with this number
echo '<font style="color:black;">Black</font>';
} else {
echo '<font style="color:white;">White</font>';
}
Also in PHP:
- Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.2.5" laravel
- capital letter php
- delete cache laravel
- Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 9263312 bytes) in /home/arsalan farooq/local security.uk/wp-includes/wp-db.php
- drupal 8 user_load
- check if someone right click javascript
- eloquent get only some columns
- envoyer mail php depuis localhost
- corsair k70 rgb mk.2
- SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long
- encode and decode data in php
- How to handle max time of execution
- #1071 - Specified key was too long; max key length is 767 bytes voyger laravel
- brew php version
- echo ternary php
- check if a word exist in a string php
- Target class [PlayerController] does not exist.
- error correction in qr code php
- doctrine fixture bundle
- apagar cache laravel
- create random string using php
- find length of string php
- Illuminate\Contracts\Container\BindingResolutionException Target class [PagesController] does not exist.
- date and hour php