fixed screenshot images size

This commit is contained in:
Doar Mihai
2026-02-28 17:21:59 +02:00
parent 8ab2d5048b
commit d2ea8b2b2f
+58 -4
View File
@@ -280,8 +280,8 @@ class IgdbService
$coverUrl = null; $coverUrl = null;
if ($cover) { if ($cover) {
$coverUrl = 'https:'.$cover->url; // Convert cover to high resolution
$coverUrl = str_replace('t_thumb', 't_cover_big', $coverUrl); $coverUrl = $this->convertToHighResolutionUrl($cover->url, 'cover');
} }
// Create or update the game // Create or update the game
@@ -319,11 +319,14 @@ class IgdbService
->get(); ->get();
foreach ($artworks as $artworkData) { foreach ($artworks as $artworkData) {
// Convert URL to high resolution
$artworkUrl = $this->convertToHighResolutionUrl($artworkData->url, 'artwork');
Artwork::updateOrCreate( Artwork::updateOrCreate(
['igdb_id' => $artworkData->id], ['igdb_id' => $artworkData->id],
[ [
'game_id' => $game->id, 'game_id' => $game->id,
'url' => $artworkData->url, 'url' => $artworkUrl,
'width' => $artworkData->width ?? null, 'width' => $artworkData->width ?? null,
'height' => $artworkData->height ?? null, 'height' => $artworkData->height ?? null,
'image_id' => $artworkData->image_id ?? null, 'image_id' => $artworkData->image_id ?? null,
@@ -350,11 +353,14 @@ class IgdbService
->get(); ->get();
foreach ($screenshots as $screenshotData) { foreach ($screenshots as $screenshotData) {
// Convert URL to high resolution
$screenshotUrl = $this->convertToHighResolutionUrl($screenshotData->url, 'screenshot');
Screenshot::updateOrCreate( Screenshot::updateOrCreate(
['igdb_id' => $screenshotData->id], ['igdb_id' => $screenshotData->id],
[ [
'game_id' => $game->id, 'game_id' => $game->id,
'url' => $screenshotData->url, 'url' => $screenshotUrl,
'width' => $screenshotData->width ?? null, 'width' => $screenshotData->width ?? null,
'height' => $screenshotData->height ?? null, 'height' => $screenshotData->height ?? null,
'image_id' => $screenshotData->image_id ?? null, 'image_id' => $screenshotData->image_id ?? null,
@@ -502,4 +508,52 @@ class IgdbService
throw $e; throw $e;
} }
} }
/**
* Convert IGDB image URL to high resolution
*
* IGDB Image Size Reference:
* - t_thumb: 90x90 (thumb)
* - t_cover_small: 90x128 (cover small)
* - t_screenshot_med: 569x320 (screenshot medium)
* - t_screenshot_big: 889x500 (screenshot big)
* - t_screenshot_huge: 1280x720 (screenshot huge)
* - t_720p: 1280x720 (720p)
* - t_1080p: 1920x1080 (1080p - highest quality)
* - t_cover_big: 264x374 (cover big)
* - t_logo_med: 284x160 (logo medium)
* - t_original: Original size (uncompressed, may be very large)
*
* @param string|null $url The IGDB image URL
* @param string $type The type of image (screenshot, artwork, cover)
* @return string|null The high resolution URL
*/
private function convertToHighResolutionUrl(?string $url, string $type = 'screenshot'): ?string
{
if (!$url) {
return null;
}
// Ensure URL has https protocol
if (strpos($url, '//') === 0) {
$url = 'https:' . $url;
} elseif (strpos($url, 'http://') === 0) {
$url = str_replace('http://', 'https://', $url);
}
// Define size mappings based on image type
$sizeMap = [
'screenshot' => 't_1080p', // 1920x1080 - best for screenshots
'artwork' => 't_1080p', // 1920x1080 - best for artwork
'cover' => 't_cover_big', // 264x374 - good balance for covers
];
$targetSize = $sizeMap[$type] ?? 't_1080p';
// Replace any existing size identifier with high resolution
$url = preg_replace('/t_[a-z_0-9]+/', $targetSize, $url);
$url = str_replace('t_thumb', 't_original', $url);
return $url;
}
} }