From bb98319217ab0b24c3c17337267a1c8b847de43a Mon Sep 17 00:00:00 2001 From: Wesley Lancel Date: Mon, 10 Oct 2016 10:56:18 +0200 Subject: [PATCH] [SeoBundle] Catch exception when OG image no longer exists --- Resources/views/SeoTwigExtension/metadata.html.twig | 6 ++++-- Twig/SeoTwigExtension.php | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Resources/views/SeoTwigExtension/metadata.html.twig b/Resources/views/SeoTwigExtension/metadata.html.twig index e8cc9ee..307438a 100644 --- a/Resources/views/SeoTwigExtension/metadata.html.twig +++ b/Resources/views/SeoTwigExtension/metadata.html.twig @@ -61,8 +61,10 @@ {% set dimensions = get_image_dimensions(imageUrl) %} - - + {% if dimensions %} + + + {% endif %} {% endif %} {% endif %} diff --git a/Twig/SeoTwigExtension.php b/Twig/SeoTwigExtension.php index d7ae7d8..6b58c97 100644 --- a/Twig/SeoTwigExtension.php +++ b/Twig/SeoTwigExtension.php @@ -244,11 +244,16 @@ public function setWebsiteTitle($websiteTitle) /** * @param $src * - * @return Seo + * @return array|null */ public function getImageDimensions($src) { - list($width, $height) = getimagesize($src); + try { + list($width, $height) = getimagesize($src); + } catch (\Exception $e) { + return null; + } + return array('width' => $width, 'height' => $height); } }