Files
HeimerdingerLoL/app/Helpers/HelperFunctions.php
Rico van Zelst ce69f0e409 refactor(helper): update image processing in HelperFunctions.php
- Replace the deprecated `Intervention\Image\ImageManagerStatic` with `Intervention\Image\ImageManager`.
- Use the `Intervention\Image\Drivers\Gd\Driver` for image manipulation.
- Update the code to read and resize images using the new ImageManager instance.
- Modify color picking logic to use the updated syntax for accessing RGB values.
2023-12-25 23:50:18 +01:00

63 lines
1.5 KiB
PHP

<?php
use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;
function getRoleIcon($roleName): string
{
$roleIcons = [
'Toplane' => 'gm-top.png',
'Jungle' => 'gm-jungle.png',
'Midlane' => 'gm-mid.png',
'Botlane' => 'gm-bot.png',
'Support' => 'gm-support.png',
];
return asset('img/' . $roleIcons[$roleName]);
}
function getAverageColorFromImageUrl($imageUrl): string
{
$imgManager = new ImageManager(new Driver());
$img = $imgManager->read(file_get_contents($imageUrl));
$img->resize(24, 24);
$totalR = 0;
$totalG = 0;
$totalB = 0;
$width = $img->width();
$height = $img->height();
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$color = $img->pickColor($x, $y);
$totalR += $color->red()->toInt();
$totalG += $color->green()->toInt();
$totalB += $color->blue()->toInt();
}
}
$pixelCount = $width * $height;
$avgR = $totalR / $pixelCount;
$avgG = $totalG / $pixelCount;
$avgB = $totalB / $pixelCount;
return sprintf("#%02x%02x%02x", $avgR, $avgG, $avgB);
}
function getRoleIconSvg($roleName): string
{
$roleIcons = [
'Toplane' => 'icon-position-top',
'Jungle' => 'icon-position-jungle',
'Midlane' => 'icon-position-middle',
'Botlane' => 'icon-position-bottom',
'Support' => 'icon-position-utility',
];
return $roleIcons[$roleName];
}