Skip to content
Permalink
Browse files

Integrate custom color with theme color

  • Loading branch information...
NEMS Linux
NEMS Linux committed Feb 26, 2019
1 parent 4fbc796 commit c9d80c957c9b2a405976e1f38ddbe4a9581ed466
Showing with 53 additions and 0 deletions.
  1. +50 −0 inc/bgcolor.php
  2. +3 −0 inc/header.php
@@ -2,6 +2,30 @@
$defaultbgcolor = '040111';
$conftmp = file('/usr/local/share/nems/nems.conf');
if (is_array($conftmp) && count($conftmp) > 0) {
foreach ($conftmp as $line) {
$tmp = explode('=',$line);
if (trim($tmp[0]) == 'background') {
$background=trim($tmp[1]);
} elseif (trim($tmp[0]) == 'backgroundColor') {
$backgroundColor=trim($tmp[1]);
}
}
}
// User has defined their own color
if ($background == 7) {
$tmp=explode(',',str_replace(array('hsv(',')'),array('',''),$backgroundColor));
$h = trim($tmp[0]);
$s = trim($tmp[1]);
$v = trim($tmp[2]);
$rgb=hsv2rgb($h,$s,$v);
$bgcolor = $rgb['html'];
} else {
$key = strtotime('today');
// caches the response each day
$cachefile = '/tmp/bgcolor-' . $key;
@@ -24,5 +48,31 @@
} else {
$bgcolor = $defaultbgcolor;
}
}
function hsv2rgb($hue,$sat,$val) {;
$rgb = array(0,0,0);
//calc rgb for 100% SV, go +1 for BR-range
for($i=0;$i<4;$i++) {
if (abs($hue - $i*120)<120) {
$distance = max(60,abs($hue - $i*120));
$rgb[$i % 3] = 1 - (($distance-60) / 60);
}
}
//desaturate by increasing lower levels
$max = max($rgb);
$factor = 255 * ($val/100);
for($i=0;$i<3;$i++) {
//use distance between 0 and max (1) and multiply with value
$rgb[$i] = round(($rgb[$i] + ($max - $rgb[$i]) * (1 - $sat/100)) * $factor);
}
$rgb['html'] = sprintf('%02X%02X%02X', $rgb[0], $rgb[1], $rgb[2]);
return $rgb;
}
?>
@@ -23,6 +23,8 @@

<!-- Favicon -->
<link rel="shortcut icon" href="/favicon.ico">

<!-- Nav bar color -->
<meta name="theme-color" content="#<?= $bgcolor ?>">

<!-- Web Fonts -->
@@ -64,6 +66,7 @@ function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
</script>

</head>

<!--

0 comments on commit c9d80c9

Please sign in to comment.
You can’t perform that action at this time.