From e7fb2eafc44d0b5eab79b13432d3e7c4227fd83e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 10 May 2017 11:03:40 +0200 Subject: [weninterface] Improve color list a bit --- inc/render.inc.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'inc/render.inc.php') diff --git a/inc/render.inc.php b/inc/render.inc.php index c34c285a..72993ab5 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -57,10 +57,11 @@ class Render if (!empty($bgcolor) || !empty($title)) { self::$header .= '"; } @@ -302,4 +303,22 @@ class Render self::$dashboard = $params; } + public static function readableColor($hex) { + if (strlen($hex) <= 4) { + $cnt = 1; + } else { + $cnt = 2; + } + if (preg_match('/^#?([a-f0-9]{'.$cnt.'})([a-f0-9]{'.$cnt.'})([a-f0-9]{'.$cnt.'})$/i', $hex, $out) != 1) + return '#000'; + $chans = array(); + $f = ($cnt === 1 ? 17 : 1); + for ($i = 1; $i <= 3; ++$i) { + $out[$i] = (hexdec($out[$i]) * $f); + $chans[] = $out[$i] ^ 0x80; + } + $b = (255 - (0.299 * $out[1] + 0.587 * $out[2] + 0.114 * $out[3])) * 2; + return sprintf("#%02x%02x%02x", ($chans[0] + $b) / 3, ($chans[1] + $b) / 3, ($chans[2] + $b) / 3); + } + } -- cgit v1.2.3-55-g7522