|
10 | 10 | use Illuminate\Support\Facades\Auth; |
11 | 11 | use Illuminate\Support\Facades\Cache; |
12 | 12 | use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
| 13 | +use Spatie\Image\Exceptions\CouldNotLoadImage; |
13 | 14 | use Spatie\Image\Image; |
14 | 15 | use Spatie\MediaLibrary\MediaCollections\Models\Media; |
15 | 16 | use Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages; |
@@ -168,32 +169,34 @@ protected function setSEOImage(Page $page) |
168 | 169 | } |
169 | 170 | } |
170 | 171 |
|
171 | | - if ($seoUrl && $imageDimensions) { |
| 172 | + if ($seoUrl && ! empty($imageDimensions)) { |
172 | 173 | SEOTools::opengraph()->addImage($seoUrl, $imageDimensions); |
173 | 174 | SEOTools::twitter()->addValue('image', $seoUrl); |
174 | 175 | } |
175 | 176 | } |
176 | 177 |
|
177 | 178 | /** |
178 | 179 | * Get the dimensions of an image with the given path. Uses cache so the image file does not need to be read each time. |
179 | | - * |
180 | | - * @return array|mixed |
181 | 180 | */ |
182 | | - protected function getSEOImageDimensions(Media $seoMedia, string $conversion) |
| 181 | + protected function getSEOImageDimensions(Media $seoMedia, string $conversion): array |
183 | 182 | { |
184 | 183 | $cacheKey = sprintf(self::CACHE_SEO_IMAGE_DIMENSIONS, $seoMedia->uuid); |
185 | 184 |
|
186 | | - return Cache::remember($cacheKey, |
187 | | - self::CACHE_SEO_IMAGE_TTL, |
188 | | - function () use ($seoMedia, $conversion) { |
189 | | - $filePath = $seoMedia->getPath($conversion); |
190 | | - $image = Image::load($filePath); |
191 | | - |
192 | | - return [ |
193 | | - 'width' => $image->getWidth(), |
194 | | - 'height' => $image->getHeight(), |
195 | | - ]; |
196 | | - }); |
| 185 | + try { |
| 186 | + return Cache::remember($cacheKey, |
| 187 | + self::CACHE_SEO_IMAGE_TTL, |
| 188 | + function () use ($seoMedia, $conversion) { |
| 189 | + $filePath = $seoMedia->getPath($conversion); |
| 190 | + $image = Image::load($filePath); |
| 191 | + |
| 192 | + return [ |
| 193 | + 'width' => $image->getWidth(), |
| 194 | + 'height' => $image->getHeight(), |
| 195 | + ]; |
| 196 | + }); |
| 197 | + } catch (CouldNotLoadImage $exception) { |
| 198 | + return []; |
| 199 | + } |
197 | 200 | } |
198 | 201 |
|
199 | 202 | private function getSettingsTitle(): string |
|
0 commit comments