Generalize @marek-guran's lighten/darkenColor functions

This commit is contained in:
billz 2023-11-29 09:16:28 +00:00
parent 7858bb5739
commit 034a0b8f63
3 changed files with 40 additions and 66 deletions

View file

@ -16,43 +16,12 @@ License: GNU General Public License v3.0
// Base color // Base color
$baseColor = $color; $baseColor = $color;
// Function to darken a color by a percentage
function darkenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));
$r = round($r * (1 - $percent));
$g = round($g * (1 - $percent));
$b = round($b * (1 - $percent));
return sprintf("#%02x%02x%02x", $r, $g, $b);
}
// Function to lighten a color by a percentage
function lightenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));
$r = round($r + (255 - $r) * $percent);
$g = round($g + (255 - $g) * $percent);
$b = round($b + (255 - $b) * $percent);
return sprintf("#%02x%02x%02x", $r, $g, $b);
}
$textColor = lightenColor($baseColor, 95); $textColor = lightenColor($baseColor, 95);
// Create other color variables // Create other color variables
$cardsColor = darkenColor($baseColor, 60); $cardsColor = darkenColor($baseColor, 60);
$secondaryColor = lightenColor($baseColor, 30); $secondaryColor = lightenColor($baseColor, 30);
$primaryColor = $baseColor; $primaryColor = $baseColor;
$backgroundColor = darkenColor($baseColor, 90); $backgroundColor = darkenColor($baseColor, 90);
?> ?>
@import url('all.css'); @import url('all.css');

View file

@ -4,7 +4,6 @@ require_once '../../includes/functions.php';
$color = getColorOpt(); $color = getColorOpt();
?> ?>
/* /*
Theme Name: Material Light Theme Name: Material Light
Author: @marek-guran Author: @marek-guran
@ -16,44 +15,12 @@ License: GNU General Public License v3.0
<?php <?php
// Base color // Base color
$baseColor = $color; $baseColor = $color;
// Function to darken a color by a percentage
function darkenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));
$r = round($r * (1 - $percent));
$g = round($g * (1 - $percent));
$b = round($b * (1 - $percent));
return sprintf("#%02x%02x%02x", $r, $g, $b);
}
// Function to lighten a color by a percentage
function lightenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));
$r = round($r + (255 - $r) * $percent);
$g = round($g + (255 - $g) * $percent);
$b = round($b + (255 - $b) * $percent);
return sprintf("#%02x%02x%02x", $r, $g, $b);
}
$textColor = lightenColor($baseColor, 95); $textColor = lightenColor($baseColor, 95);
// Create other color variables // Create other color variables
$cardsColor = lightenColor($baseColor, 50); $cardsColor = lightenColor($baseColor, 50);
$secondaryColor = lightenColor($baseColor, 30); $secondaryColor = lightenColor($baseColor, 30);
$primaryColor = $baseColor; $primaryColor = $baseColor;
$backgroundColor = lightenColor($baseColor, 60); $backgroundColor = lightenColor($baseColor, 60);
?> ?>
@import url('all.css'); @import url('all.css');

View file

@ -715,10 +715,10 @@ function getColorOpt()
$color = "#2b8080"; $color = "#2b8080";
} else { } else {
$color = $_COOKIE['color']; $color = $_COOKIE['color'];
setcookie('color', $color);
} }
return $color; return $color;
} }
function getSidebarState() function getSidebarState()
{ {
if(isset($_COOKIE['sidebarToggled'])) { if(isset($_COOKIE['sidebarToggled'])) {
@ -784,7 +784,7 @@ function validate_host($host)
// @return boolean // @return boolean
function getNightmode() function getNightmode()
{ {
if (isset($_COOKIE['theme']) && $_COOKIE['theme'] == 'lightsout.css') { if (isset($_COOKIE['theme']) && $_COOKIE['theme'] == 'lightsout.php') {
return true; return true;
} else { } else {
return false; return false;
@ -924,3 +924,41 @@ function checkReleaseVersion($installed, $latest) {
return false; return false;
} }
/**
* Function to darken a color by a percentage
* From @marek-guran's material-dark theme for RaspAP
* Author URI: https://github.com/marek-guran
*/
function darkenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));
$r = round($r * (1 - $percent));
$g = round($g * (1 - $percent));
$b = round($b * (1 - $percent));
return sprintf("#%02x%02x%02x", $r, $g, $b);
}
/**
* Function to lighten a color by a percentage
* From @marek-guran's material-dark theme for RaspAP
* Author URI: https://github.com/marek-guran
*/
function lightenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));
$r = round($r + (255 - $r) * $percent);
$g = round($g + (255 - $g) * $percent);
$b = round($b + (255 - $b) * $percent);
return sprintf("#%02x%02x%02x", $r, $g, $b);
}