From fbca800246e66df7870f546abcc6da71d938c952 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 29 Mar 2017 10:34:33 +0200 Subject: [PATCH] FIX Detection of color brightness --- htdocs/core/class/html.formother.class.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 4ac3eb99c50..7e78f7bbe4d 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -604,10 +604,22 @@ class FormOther $textcolor='FFF'; if ($color) { - $hex=$color; - $r = hexdec($hex[0].$hex[1]); - $g = hexdec($hex[2].$hex[3]); - $b = hexdec($hex[4].$hex[5]); + $tmp=explode(',', $color); + if (count($tmp) > 1) // This is a comma RGB ('255','255','255') + { + $r = $tmp[0]; + $g = $tmp[1]; + $b = $tmp[2]; + } + else + { + $hexr=$color[0].$color[1]; + $hexg=$color[2].$color[3]; + $hexb=$color[4].$color[5]; + $r = hexdec($hexr); + $g = hexdec($hexg); + $b = hexdec($hexb); + } $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm if ($bright > 0.6) $textcolor='000'; }