From d727455e96a9950e710a3a6e160cab527278f0b3 Mon Sep 17 00:00:00 2001 From: Julian Prieber Date: Mon, 13 Feb 2023 20:02:56 +0100 Subject: [PATCH] Fixed error Call to undefined function exif_imagetype() (View: /htdocs/resources/views/littlelink.blade.php) --- app/Functions/findfile.php | 90 +++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/app/Functions/findfile.php b/app/Functions/findfile.php index c3c7bbb..8118784 100644 --- a/app/Functions/findfile.php +++ b/app/Functions/findfile.php @@ -24,47 +24,55 @@ function findBackground($name){ 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"; + $file = base_path('/img/background-img/'.$file); + + // Get image information using getimagesize + $imageInfo = getimagesize($file); + if (!$imageInfo) { + echo "Error: Unable to get image information.\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; + } + + // 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: + 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'; } } - $avg_brightness = $total_brightness / ($width * $height); - - // Determine if the image is more dark or light - if ($avg_brightness < 128) { - return 'dark'; - } else { - return 'light'; - } -} +