diff --git a/app/Functions/findfile.php b/app/Functions/findfile.php index 223213a..c3c7bbb 100644 --- a/app/Functions/findfile.php +++ b/app/Functions/findfile.php @@ -20,4 +20,51 @@ function findBackground($name){ $pathinfo = $name. "." . pathinfo($file, PATHINFO_EXTENSION); }} return $pathinfo; -} \ No newline at end of file +} + +function analyzeImageBrightness($file) { + + $file = base_path('/img/background-img/'.$file); + + // Get the image type + $type = exif_imagetype($file); + + // Load the image based on its type + switch ($type) { + case IMAGETYPE_JPEG: + case IMAGETYPE_JPEG2000: + $img = imagecreatefromjpeg($file); + break; + case IMAGETYPE_PNG: + $img = imagecreatefrompng($file); + break; + default: + echo "Error: Unsupported image type.\n"; + exit(); + } + + // Get image dimensions + $width = imagesx($img); + $height = imagesy($img); + + // Calculate the average brightness of the image + $total_brightness = 0; + for ($x=0; $x<$width; $x++) { + for ($y=0; $y<$height; $y++) { + $rgb = imagecolorat($img, $x, $y); + $r = ($rgb >> 16) & 0xFF; + $g = ($rgb >> 8) & 0xFF; + $b = $rgb & 0xFF; + $brightness = (int)(($r + $g + $b) / 3); + $total_brightness += $brightness; + } + } + $avg_brightness = $total_brightness / ($width * $height); + + // Determine if the image is more dark or light + if ($avg_brightness < 128) { + return 'dark'; + } else { + return 'light'; + } +} diff --git a/resources/views/littlelink.blade.php b/resources/views/littlelink.blade.php index 7136e0f..49370d5 100644 --- a/resources/views/littlelink.blade.php +++ b/resources/views/littlelink.blade.php @@ -44,10 +44,22 @@ return $path;} @endif -@if(file_exists(base_path('/img/background-img/'.findBackground($userinfo->id)))) + +@php +$customBackgroundFile = findBackground($userinfo->id); +$customBackgroundPath = base_path('/img/background-img/'.$customBackgroundFile); +$customBackgroundURL = url('/img/background-img/'.$customBackgroundFile); +$customBackgroundExists = file_exists($customBackgroundPath); +if($customBackgroundExists == true){ + $customBackgroundBrightness = analyzeImageBrightness($customBackgroundFile); + } else { + $customBackgroundBrightness == false;} +@endphp + +@if($customBackgroundExists == true) + @elseif ($customBackgroundExists == true and $customBackgroundBrightness == 'light') + + + @elseif ($color_scheme_override == 'dark') @elseif ($color_scheme_override == 'light')