Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-01-04 19:35:56 +0300
committerJulius Härtl <jus@bitgrid.net>2018-01-08 12:31:34 +0300
commite4f9c75a050a861550885af0eb33ead9e8778859 (patch)
tree302b80792a5ff2cd225f3cee3d8bb43e2c844320 /apps/theming/lib/Util.php
parentecf885046459253fbe4599600db241b9e36fa61a (diff)
Adjust theming color calculations using sRGB luma
based on https://robots.thoughtbot.com/closer-look-color-lightness Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/theming/lib/Util.php')
-rw-r--r--apps/theming/lib/Util.php35
1 files changed, 27 insertions, 8 deletions
diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php
index 194b5eeb0d0..6a1aa672108 100644
--- a/apps/theming/lib/Util.php
+++ b/apps/theming/lib/Util.php
@@ -63,8 +63,8 @@ class Util {
* @return bool
*/
public function invertTextColor($color) {
- $l = $this->calculateLuminance($color);
- if($l>0.55) {
+ $l = $this->calculateLuma($color);
+ if($l>0.6) {
return true;
} else {
return false;
@@ -90,6 +90,26 @@ class Util {
* @return float
*/
public function calculateLuminance($color) {
+ list($red, $green, $blue) = $this->hexToRGB($color);
+ $compiler = new Compiler();
+ $hsl = $compiler->toHSL($red, $green, $blue);
+ return $hsl[3]/100;
+ }
+
+ /**
+ * @param string $color rgb color value
+ * @return float
+ */
+ public function calculateLuma($color) {
+ list($red, $green, $blue) = $this->hexToRGB($color);
+ return (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue) / 255;
+ }
+
+ /**
+ * @param string $color rgb color value
+ * @return int[]
+ */
+ public function hexToRGB($color) {
$hex = preg_replace("/[^0-9A-Fa-f]/", '', $color);
if (strlen($hex) === 3) {
$hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2};
@@ -97,12 +117,11 @@ class Util {
if (strlen($hex) !== 6) {
return 0;
}
- $red = hexdec(substr($hex, 0, 2));
- $green = hexdec(substr($hex, 2, 2));
- $blue = hexdec(substr($hex, 4, 2));
- $compiler = new Compiler();
- $hsl = $compiler->toHSL($red, $green, $blue);
- return $hsl[3]/100;
+ return [
+ hexdec(substr($hex, 0, 2)),
+ hexdec(substr($hex, 2, 2)),
+ hexdec(substr($hex, 4, 2))
+ ];
}
/**