 .../responsive_image/responsive_image.module       | 92 ----------------------
 .../templates/responsive-image.html.twig           |  4 +-
 core/themes/stable/stable.theme                    | 91 +++++++++++++++++++++
 .../templates/field/responsive-image.html.twig     |  2 +-
 4 files changed, 95 insertions(+), 94 deletions(-)

diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module
index 7df1da8..394fc80 100644
--- a/core/modules/responsive_image/responsive_image.module
+++ b/core/modules/responsive_image/responsive_image.module
@@ -131,98 +131,6 @@ function template_preprocess_responsive_image_formatter(&$variables) {
 }
 
 /**
- * Prepares variables for a responsive image.
- *
- * Default template: responsive-image.html.twig.
- *
- * @param $variables
- *   An associative array containing:
- *   - uri: The URI of the image.
- *   - width: The width of the image (if known).
- *   - height: The height of the image (if known).
- *   - attributes: Associative array of attributes to be placed in the img tag.
- *   - responsive_image_style_id: The ID of the responsive image style.
- */
-function template_preprocess_responsive_image(&$variables) {
-  // Make sure that width and height are proper values
-  // If they exists we'll output them
-  // @see http://www.w3.org/community/respimg/2012/06/18/florians-compromise/
-  if (isset($variables['width']) && empty($variables['width'])) {
-    unset($variables['width']);
-    unset($variables['height']);
-  }
-  elseif (isset($variables['height']) && empty($variables['height'])) {
-    unset($variables['width']);
-    unset($variables['height']);
-  }
-
-  $image = \Drupal::service('image.factory')->get($variables['uri']);
-  $responsive_image_style = ResponsiveImageStyle::load($variables['responsive_image_style_id']);
-  // If a responsive image style is not selected, log the error and stop
-  // execution.
-  if (!$responsive_image_style) {
-    $variables['img_element'] = [];
-    \Drupal::logger('responsive_image')->log(\Drupal\Core\Logger\RfcLogLevel::ERROR, 'Failed to load responsive image style: “@style“ while displaying responsive image.', ['@style' => $variables['responsive_image_style_id']]);
-    return;
-  }
-  // Retrieve all breakpoints and multipliers and reverse order of breakpoints.
-  // By default, breakpoints are ordered from smallest weight to largest:
-  // the smallest weight is expected to have the smallest breakpoint width,
-  // while the largest weight is expected to have the largest breakpoint
-  // width. For responsive images, we need largest breakpoint widths first, so
-  // we need to reverse the order of these breakpoints.
-  $breakpoints = array_reverse(\Drupal::service('breakpoint.manager')->getBreakpointsByGroup($responsive_image_style->getBreakpointGroup()));
-  foreach ($responsive_image_style->getKeyedImageStyleMappings() as $breakpoint_id => $multipliers) {
-    if (isset($breakpoints[$breakpoint_id])) {
-      $variables['sources'][] = responsive_image_build_source_attributes($image, $variables, $breakpoints[$breakpoint_id], $multipliers);
-    }
-  }
-
-  if (isset($variables['sources']) && count($variables['sources']) === 1 && !isset($variables['sources'][0]['media'])) {
-    // There is only one source tag with an empty media attribute. This means
-    // we can output an image tag with the srcset attribute in stead of a
-    // picture tag.
-    $variables['output_image_tag'] = TRUE;
-    foreach ($variables['sources'][0] as $attribute => $value) {
-      if ($attribute != 'type') {
-        $variables['attributes'][$attribute] = $value;
-      }
-    }
-    $variables['img_element'] = array(
-      '#theme' => 'image',
-      '#uri' => _responsive_image_image_style_url($responsive_image_style->getFallbackImageStyle(), $image->getSource()),
-    );
-  }
-  else {
-    $variables['output_image_tag'] = FALSE;
-    // Prepare the fallback image. Use srcset in the fallback image to avoid
-    // unnecessary preloading of images in older browsers. See
-    // http://scottjehl.github.io/picturefill/#using-picture and
-    // http://scottjehl.github.io/picturefill/#gotchas for more information.
-    $variables['img_element'] = array(
-      '#theme' => 'image',
-      '#srcset' => array(
-        array(
-          'uri' => _responsive_image_image_style_url($responsive_image_style->getFallbackImageStyle(), $image->getSource()),
-        ),
-      ),
-    );
-  }
-
-  if (isset($variables['attributes'])) {
-    if (isset($variables['attributes']['alt'])) {
-      $variables['img_element']['#alt'] = $variables['attributes']['alt'];
-      unset($variables['attributes']['alt']);
-    }
-    if (isset($variables['attributes']['title'])) {
-      $variables['img_element']['#title'] = $variables['attributes']['title'];
-      unset($variables['attributes']['title']);
-    }
-    $variables['img_element']['#attributes'] = $variables['attributes'];
-  }
-}
-
-/**
  * Helper function for template_preprocess_responsive_image().
  *
  * Builds an array of attributes for <source> tags to be used in a <picture>
diff --git a/core/modules/responsive_image/templates/responsive-image.html.twig b/core/modules/responsive_image/templates/responsive-image.html.twig
index 99fca6b..d8b746c 100644
--- a/core/modules/responsive_image/templates/responsive-image.html.twig
+++ b/core/modules/responsive_image/templates/responsive-image.html.twig
@@ -10,11 +10,13 @@
  *   <picture> tag.
  *
  * @see template_preprocess()
- * @see template_preprocess_responsive_image()
  *
  * @ingroup themeable
  */
 #}
+{% spaceless %}
+  {# @TODO move template_preprocess_responsive_image() in here!#}
+{% endspaceless %}
 {% if output_image_tag %}
   {{ img_element }}
 {% else %}
diff --git a/core/themes/stable/stable.theme b/core/themes/stable/stable.theme
index 8022352..459b27a 100644
--- a/core/themes/stable/stable.theme
+++ b/core/themes/stable/stable.theme
@@ -6,6 +6,7 @@
  */
 
 use Drupal\Component\Utility\Html;
+use Drupal\responsive_image\Entity\ResponsiveImageStyle;
 
 /**
  * Implements template_preprocess_links().
@@ -137,3 +138,93 @@ function stable_preprocess_form_element_label(&$variables) {
   // Pass elements required to template.
   $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;
 }
+
+/**
+ * Prepares variables for a responsive image.
+ *
+ * @param $variables
+ *   An associative array containing:
+ *   - uri: The URI of the image.
+ *   - width: The width of the image (if known).
+ *   - height: The height of the image (if known).
+ *   - attributes: Associative array of attributes to be placed in the img tag.
+ *   - responsive_image_style_id: The ID of the responsive image style.
+ */
+function stable_preprocess_responsive_image(&$variables) {
+  // Make sure that width and height are proper values
+  // If they exists we'll output them
+  // @see http://www.w3.org/community/respimg/2012/06/18/florians-compromise/
+  if (isset($variables['width']) && empty($variables['width'])) {
+    unset($variables['width']);
+    unset($variables['height']);
+  }
+  elseif (isset($variables['height']) && empty($variables['height'])) {
+    unset($variables['width']);
+    unset($variables['height']);
+  }
+
+  $image = \Drupal::service('image.factory')->get($variables['uri']);
+  $responsive_image_style = ResponsiveImageStyle::load($variables['responsive_image_style_id']);
+  // If a responsive image style is not selected, log the error and stop
+  // execution.
+  if (!$responsive_image_style) {
+    $variables['img_element'] = [];
+    \Drupal::logger('responsive_image')->log(\Drupal\Core\Logger\RfcLogLevel::ERROR, 'Failed to load responsive image style: “@style“ while displaying responsive image.', ['@style' => $variables['responsive_image_style_id']]);
+    return;
+  }
+  // Retrieve all breakpoints and multipliers and reverse order of breakpoints.
+  // By default, breakpoints are ordered from smallest weight to largest:
+  // the smallest weight is expected to have the smallest breakpoint width,
+  // while the largest weight is expected to have the largest breakpoint
+  // width. For responsive images, we need largest breakpoint widths first, so
+  // we need to reverse the order of these breakpoints.
+  $breakpoints = array_reverse(\Drupal::service('breakpoint.manager')->getBreakpointsByGroup($responsive_image_style->getBreakpointGroup()));
+  foreach ($responsive_image_style->getKeyedImageStyleMappings() as $breakpoint_id => $multipliers) {
+    if (isset($breakpoints[$breakpoint_id])) {
+      $variables['sources'][] = responsive_image_build_source_attributes($image, $variables, $breakpoints[$breakpoint_id], $multipliers);
+    }
+  }
+
+  if (isset($variables['sources']) && count($variables['sources']) === 1 && !isset($variables['sources'][0]['media'])) {
+    // There is only one source tag with an empty media attribute. This means
+    // we can output an image tag with the srcset attribute in stead of a
+    // picture tag.
+    $variables['output_image_tag'] = TRUE;
+    foreach ($variables['sources'][0] as $attribute => $value) {
+      if ($attribute != 'type') {
+        $variables['attributes'][$attribute] = $value;
+      }
+    }
+    $variables['img_element'] = array(
+      '#theme' => 'image',
+      '#uri' => _responsive_image_image_style_url($responsive_image_style->getFallbackImageStyle(), $image->getSource()),
+    );
+  }
+  else {
+    $variables['output_image_tag'] = FALSE;
+    // Prepare the fallback image. Use srcset in the fallback image to avoid
+    // unnecessary preloading of images in older browsers. See
+    // http://scottjehl.github.io/picturefill/#using-picture and
+    // http://scottjehl.github.io/picturefill/#gotchas for more information.
+    $variables['img_element'] = array(
+      '#theme' => 'image',
+      '#srcset' => array(
+        array(
+          'uri' => _responsive_image_image_style_url($responsive_image_style->getFallbackImageStyle(), $image->getSource()),
+        ),
+      ),
+    );
+  }
+
+  if (isset($variables['attributes'])) {
+    if (isset($variables['attributes']['alt'])) {
+      $variables['img_element']['#alt'] = $variables['attributes']['alt'];
+      unset($variables['attributes']['alt']);
+    }
+    if (isset($variables['attributes']['title'])) {
+      $variables['img_element']['#title'] = $variables['attributes']['title'];
+      unset($variables['attributes']['title']);
+    }
+    $variables['img_element']['#attributes'] = $variables['attributes'];
+  }
+}
diff --git a/core/themes/stable/templates/field/responsive-image.html.twig b/core/themes/stable/templates/field/responsive-image.html.twig
index ae77ffb..398b219 100644
--- a/core/themes/stable/templates/field/responsive-image.html.twig
+++ b/core/themes/stable/templates/field/responsive-image.html.twig
@@ -10,7 +10,7 @@
  *   <picture> tag.
  *
  * @see template_preprocess()
- * @see template_preprocess_responsive_image()
+ * @see stable_preprocess_responsive_image()
  */
 #}
 {% if output_image_tag %}
