From 51e4f4e2f7049d57c433a5a69f09fe17e11abd22 Mon Sep 17 00:00:00 2001 From: Dominik Chrastecky Date: Sun, 18 Feb 2024 22:12:38 +0100 Subject: [PATCH] Catch exception --- src/Service/ImageFetcher.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Service/ImageFetcher.php b/src/Service/ImageFetcher.php index 74826f3..d27b903 100644 --- a/src/Service/ImageFetcher.php +++ b/src/Service/ImageFetcher.php @@ -5,6 +5,7 @@ use DateInterval; use Psr\Cache\CacheItemPoolInterface; use SapientPro\ImageComparator\ImageComparator; +use Symfony\Component\ErrorHandler\Error\FatalError; use Symfony\Component\HttpFoundation\Request; use Symfony\Contracts\Cache\ItemInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -32,8 +33,12 @@ public function getImageHash(string $url): ?string } else { $contentType = $response->getHeaders(false)['content-type'][0] ?? ''; if (str_starts_with($contentType, 'image/')) { - $image = @imagecreatefromstring($response->getContent()); - error_clear_last(); + try { + $image = @imagecreatefromstring($response->getContent()); + } catch (FatalError) { + // ignore that stupidity + $image = false; + } if ($image !== false) { $cacheItem->set( $this->imageComparator->convertHashToBinaryString(