LinkStack/app/Functions/findfile.php

98 lines
3.2 KiB
PHP

<?php
function findFile($name){
$directory = base_path('/assets/linkstack/images/');
$files = scandir($directory);
$pathinfo = "error.error";
foreach($files as $file) {
if (strpos($file, $name.'.') !== false) {
$pathinfo = $name. "." . pathinfo($file, PATHINFO_EXTENSION);
}}
return $pathinfo;
}
function findAvatar($name){
$directory = base_path('assets/img');
$files = scandir($directory);
$pathinfo = "error.error";
foreach($files as $file) {
if (strpos($file, $name.'.') !== false) {
$pathinfo = "assets/img/" . $name. "." . pathinfo($file, PATHINFO_EXTENSION);
}}
return $pathinfo;
}
function findBackground($name){
$directory = base_path('assets/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;
}
function analyzeImageBrightness($file) {
$file = base_path('assets/img/background-img/'.$file);
// Get image information using getimagesize
$imageInfo = getimagesize($file);
if (!$imageInfo) {
return 'dark';
}
// 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:
return 'dark';
}
// 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';
}
}
function infoIcon($tip) {
echo '
<div class="d-flex justify-content-center align-items-center">
<a data-bs-toggle="tooltip" data-bs-placement="bottom" title="' . $tip . '">
<svg class="icon-32" width="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.67 1.99927H16.34C19.73 1.99927 22 4.37927 22 7.91927V16.0903C22 19.6203 19.73 21.9993 16.34 21.9993H7.67C4.28 21.9993 2 19.6203 2 16.0903V7.91927C2 4.37927 4.28 1.99927 7.67 1.99927ZM11.99 9.06027C11.52 9.06027 11.13 8.66927 11.13 8.19027C11.13 7.70027 11.52 7.31027 12.01 7.31027C12.49 7.31027 12.88 7.70027 12.88 8.19027C12.88 8.66927 12.49 9.06027 11.99 9.06027ZM12.87 15.7803C12.87 16.2603 12.48 16.6503 11.99 16.6503C11.51 16.6503 11.12 16.2603 11.12 15.7803V11.3603C11.12 10.8793 11.51 10.4803 11.99 10.4803C12.48 10.4803 12.87 10.8793 12.87 11.3603V15.7803Z" fill="currentColor"></path>
</svg>
</a>
</div>
';
}