Fixed error
Call to undefined function exif_imagetype() (View: /htdocs/resources/views/littlelink.blade.php)
This commit is contained in:
parent
dd722620cb
commit
d727455e96
|
@ -24,47 +24,55 @@ function findBackground($name){
|
||||||
|
|
||||||
function analyzeImageBrightness($file) {
|
function analyzeImageBrightness($file) {
|
||||||
|
|
||||||
$file = base_path('/img/background-img/'.$file);
|
$file = base_path('/img/background-img/'.$file);
|
||||||
|
|
||||||
// Get the image type
|
// Get image information using getimagesize
|
||||||
$type = exif_imagetype($file);
|
$imageInfo = getimagesize($file);
|
||||||
|
if (!$imageInfo) {
|
||||||
// Load the image based on its type
|
echo "Error: Unable to get image information.\n";
|
||||||
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();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get image dimensions
|
// Get the image type
|
||||||
$width = imagesx($img);
|
$type = $imageInfo[2];
|
||||||
$height = imagesy($img);
|
|
||||||
|
|
||||||
// Calculate the average brightness of the image
|
// Load the image based on its type
|
||||||
$total_brightness = 0;
|
switch ($type) {
|
||||||
for ($x=0; $x<$width; $x++) {
|
case IMAGETYPE_JPEG:
|
||||||
for ($y=0; $y<$height; $y++) {
|
case IMAGETYPE_JPEG2000:
|
||||||
$rgb = imagecolorat($img, $x, $y);
|
$img = imagecreatefromjpeg($file);
|
||||||
$r = ($rgb >> 16) & 0xFF;
|
break;
|
||||||
$g = ($rgb >> 8) & 0xFF;
|
case IMAGETYPE_PNG:
|
||||||
$b = $rgb & 0xFF;
|
$img = imagecreatefrompng($file);
|
||||||
$brightness = (int)(($r + $g + $b) / 3);
|
break;
|
||||||
$total_brightness += $brightness;
|
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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue