From d2ea8b2b2f2fd629dc6d340c1fce3bb3a9485294 Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sat, 28 Feb 2026 17:21:59 +0200 Subject: [PATCH] fixed screenshot images size --- app/Services/IgdbService.php | 62 +++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/app/Services/IgdbService.php b/app/Services/IgdbService.php index 9c16f79..0e76e6d 100644 --- a/app/Services/IgdbService.php +++ b/app/Services/IgdbService.php @@ -280,8 +280,8 @@ class IgdbService $coverUrl = null; if ($cover) { - $coverUrl = 'https:'.$cover->url; - $coverUrl = str_replace('t_thumb', 't_cover_big', $coverUrl); + // Convert cover to high resolution + $coverUrl = $this->convertToHighResolutionUrl($cover->url, 'cover'); } // Create or update the game @@ -319,11 +319,14 @@ class IgdbService ->get(); foreach ($artworks as $artworkData) { + // Convert URL to high resolution + $artworkUrl = $this->convertToHighResolutionUrl($artworkData->url, 'artwork'); + Artwork::updateOrCreate( ['igdb_id' => $artworkData->id], [ 'game_id' => $game->id, - 'url' => $artworkData->url, + 'url' => $artworkUrl, 'width' => $artworkData->width ?? null, 'height' => $artworkData->height ?? null, 'image_id' => $artworkData->image_id ?? null, @@ -350,11 +353,14 @@ class IgdbService ->get(); foreach ($screenshots as $screenshotData) { + // Convert URL to high resolution + $screenshotUrl = $this->convertToHighResolutionUrl($screenshotData->url, 'screenshot'); + Screenshot::updateOrCreate( ['igdb_id' => $screenshotData->id], [ 'game_id' => $game->id, - 'url' => $screenshotData->url, + 'url' => $screenshotUrl, 'width' => $screenshotData->width ?? null, 'height' => $screenshotData->height ?? null, 'image_id' => $screenshotData->image_id ?? null, @@ -502,4 +508,52 @@ class IgdbService 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; + } }