Dieses PHP-Script liefert die passende Textfarbe (weiß oder schwarz) zu einer gegebenen RGB-Farbe.
<?php
/*
This Software returns a suitable text color of a given rgb background color.
Copyright (C) 2020 Guido Richter / tintenkobold.de
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License [http://www.gnu.org/licenses/] for more details.
*/
function text_color_fit_rgb($r,$g,$b)
{
$y = 0.299 * $r + 0.587 * $g + 0.114 * $b;
if($y<=(255/2)) return array(255,255,255);
else return array(0,0,0);
}
?>