fix: Handle exceptions in image processing functions

- Catch exceptions when reading image content to prevent errors.
- Adjust image resizing dimensions for better display.
This commit is contained in:
Rico van Zelst
2024-03-28 10:34:16 +01:00
parent 5b55e21659
commit 998f386f20
3 changed files with 13 additions and 9 deletions

View File

@@ -13,16 +13,20 @@ function getRoleIcon($roleName): string
'Support' => 'gm-support.png',
];
return asset('img/'.$roleIcons[$roleName]);
return asset('img/' . $roleIcons[$roleName]);
}
function getAverageColorFromImageUrl($imageUrl): string
{
$imgManager = new ImageManager(new Driver());
$img = $imgManager->read(file_get_contents($imageUrl));
try {
$img = $imgManager->read(file_get_contents($imageUrl));
} catch (Exception $e) {
return '#904f2c';
}
$img->resize(24, 24);
$img->resize(32, 32);
$totalR = 0;
$totalG = 0;