Skip to content

Commit

Permalink
[SeoBundle] Catch exception when OG image no longer exists
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleylancel committed Oct 10, 2016
1 parent 88d3b48 commit bb98319
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Resources/views/SeoTwigExtension/metadata.html.twig
Expand Up @@ -61,8 +61,10 @@
{% set dimensions = get_image_dimensions(imageUrl) %}
<meta property="og:image" content="{{ asset(imageUrl) }}">
<meta property="og:image:type" content="{{ seo.ogImage.contentType }}">
<meta property="og:image:height" content="{{ dimensions.height }}">
<meta property="og:image:width" content="{{ dimensions.width }}">
{% if dimensions %}
<meta property="og:image:height" content="{{ dimensions.height }}">
<meta property="og:image:width" content="{{ dimensions.width }}">
{% endif %}
<link rel="image_src" href="{{ asset(imageUrl) }}"/>
{% endif %}
{% endif %}
Expand Down
9 changes: 7 additions & 2 deletions Twig/SeoTwigExtension.php
Expand Up @@ -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);
}
}

0 comments on commit bb98319

Please sign in to comment.