diff --git a/modules/views_rss_core/views_rss_core.inc b/modules/views_rss_core/views_rss_core.inc index 8968963..ecb5f4f 100644 --- a/modules/views_rss_core/views_rss_core.inc +++ b/modules/views_rss_core/views_rss_core.inc @@ -310,15 +310,18 @@ function views_rss_core_preprocess_item_enclosure(&$variables) { // If the derivative doesn't exist yet, we won't be able to get its size // to add it to the 'length' attribute, so we need to create it first. + $check_file_size = TRUE; if (!file_exists($image_style_uri)) { - $image_style->createDerivative($image_uri, $image_style_uri); + $check_file_size = $image_style->createDerivative($image_uri, $image_style_uri); } $element['attributes'] = [ 'url' => $image_style->buildUrl($image_uri), - 'length' => filesize($image_style_uri), 'type' => $file->getMimeType(), ]; + if ($check_file_size) { + $element['attributes']['length'] = filesize($image_style_uri); + } } // Normal image size. else { diff --git a/modules/views_rss_media/views_rss_media.inc b/modules/views_rss_media/views_rss_media.inc index 2a8fa48..b2434ee 100644 --- a/modules/views_rss_media/views_rss_media.inc +++ b/modules/views_rss_media/views_rss_media.inc @@ -40,13 +40,23 @@ function views_rss_media_preprocess_item_content(&$variables) { // Image style is defined, need to link to resized version. if ($image_style_name = $item['rendered']['#image_style']) { $image_style = ImageStyle::load($image_style_name); - $uri = $image_style->buildUri($file->getFileUri()); + $image_style_uri = $image_style->buildUri($file->getFileUri()); $url = $image_style->buildUrl($file->getFileUri()); + + // If the derivative doesn't exist yet, we won't be able to get its size + // to add it to the 'length' attribute, so we need to create it first. + $check_file_size = TRUE; + if (!file_exists($image_style_uri)) { + $check_file_size = $image_style->createDerivative($image_style_uri, $image_style_uri); + } + $element['attributes'] = [ 'url' => $url, - 'fileSize' => filesize(\Drupal::service('file_system')->realpath($uri)), 'type' => $mime_type, ]; + if ($check_file_size) { + $element['attributes']['fileSize'] = filesize($image_style_uri); + } } // Normal image size. else {