2022-12-22 09:51:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function findFile($name){
|
|
|
|
$directory = base_path('/littlelink/images/');
|
|
|
|
$files = scandir($directory);
|
|
|
|
$pathinfo = "error.error";
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (strpos($file, $name.'.') !== false) {
|
|
|
|
$pathinfo = $name. "." . pathinfo($file, PATHINFO_EXTENSION);
|
|
|
|
}}
|
|
|
|
return $pathinfo;
|
2023-02-13 17:18:32 +01:00
|
|
|
}
|
|
|
|
|
2023-03-08 22:03:54 +01:00
|
|
|
function findAvatar($name){
|
|
|
|
$directory = base_path('/img');
|
|
|
|
$files = scandir($directory);
|
|
|
|
$pathinfo = "error.error";
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (strpos($file, $name.'.') !== false) {
|
|
|
|
$pathinfo = "/img/" . $name. "." . pathinfo($file, PATHINFO_EXTENSION);
|
|
|
|
}}
|
|
|
|
return $pathinfo;
|
|
|
|
}
|
|
|
|
|
2023-02-13 17:18:32 +01:00
|
|
|
function findBackground($name){
|
|
|
|
$directory = base_path('/img/background-img/');
|
|
|
|
$files = scandir($directory);
|
|
|
|
$pathinfo = "error.error";
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (strpos($file, $name.'.') !== false) {
|
|
|
|
$pathinfo = $name. "." . pathinfo($file, PATHINFO_EXTENSION);
|
|
|
|
}}
|
|
|
|
return $pathinfo;
|
2023-02-13 18:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function analyzeImageBrightness($file) {
|
|
|
|
|
2023-02-13 20:02:56 +01:00
|
|
|
$file = base_path('/img/background-img/'.$file);
|
|
|
|
|
|
|
|
// Get image information using getimagesize
|
|
|
|
$imageInfo = getimagesize($file);
|
|
|
|
if (!$imageInfo) {
|
2023-02-13 21:12:44 +01:00
|
|
|
return 'dark';
|
2023-02-13 20:02:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the image type
|
|
|
|
$type = $imageInfo[2];
|
|
|
|
|
|
|
|
// 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:
|
2023-02-13 21:12:44 +01:00
|
|
|
return 'dark';
|
2023-02-13 20:02:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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';
|
2023-02-13 18:10:13 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-13 20:02:56 +01:00
|
|
|
|