diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php
index 4c3a27d..e3ade5e 100644
--- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php
+++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php
@@ -5,11 +5,13 @@
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Field\FieldItemListInterface;
 use Drupal\Core\Field\FieldDefinitionInterface;
+use Drupal\Core\Image\ImageFactory;
 use Drupal\Core\Link;
 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\Core\Url;
 use Drupal\image\Entity\ImageStyle;
+use Drupal\file\FileInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Cache\Cache;
@@ -42,6 +44,13 @@ class ImageFormatter extends ImageFormatterBase implements ContainerFactoryPlugi
   protected $imageStyleStorage;
 
   /**
+   * The image factory service.
+   *
+   * @var \Drupal\Core\Image\ImageFactory
+   */
+  protected $imageFactory;
+
+  /**
    * Constructs an ImageFormatter object.
    *
    * @param string $plugin_id
@@ -61,10 +70,11 @@ class ImageFormatter extends ImageFormatterBase implements ContainerFactoryPlugi
    * @param \Drupal\Core\Session\AccountInterface $current_user
    *   The current user.
    */
-  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, EntityStorageInterface $image_style_storage) {
+  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, EntityStorageInterface $image_style_storage, ImageFactory $image_factory) {
     parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
     $this->currentUser = $current_user;
     $this->imageStyleStorage = $image_style_storage;
+    $this->imageFactory = $image_factory;
   }
 
   /**
@@ -80,7 +90,8 @@ public static function create(ContainerInterface $container, array $configuratio
       $configuration['view_mode'],
       $configuration['third_party_settings'],
       $container->get('current_user'),
-      $container->get('entity.manager')->getStorage('image_style')
+      $container->get('entity.manager')->getStorage('image_style'),
+      $container->get('image.factory')
     );
   }
 
@@ -185,15 +196,12 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
       $link_file = TRUE;
     }
 
-    $image_style_setting = $this->getSetting('image_style');
-
-    // Collect cache tags to be added for each item in the field.
-    $base_cache_tags = [];
-    if (!empty($image_style_setting)) {
-      $image_style = $this->imageStyleStorage->load($image_style_setting);
-      $base_cache_tags = $image_style->getCacheTags();
+    $image_style_id = $this->getSetting('image_style');
+    if ($image_style_id) {
+      $image_style = $this->imageStyleStorage->load($image_style_id);
     }
 
+    /** @var FileInterface $file */
     foreach ($files as $delta => $file) {
       $cache_contexts = [];
       if (isset($link_file)) {
@@ -206,7 +214,6 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
         $url = Url::fromUri(file_create_url($image_uri));
         $cache_contexts[] = 'url.site';
       }
-      $cache_tags = Cache::mergeTags($base_cache_tags, $file->getCacheTags());
 
       // Extract field item attributes for the theme function, and unset them
       // from the $item so that the field template does not re-render them.
@@ -218,13 +225,20 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
         '#theme' => 'image_formatter',
         '#item' => $item,
         '#item_attributes' => $item_attributes,
-        '#image_style' => $image_style_setting,
         '#url' => $url,
         '#cache' => array(
-          'tags' => $cache_tags,
+          // Always use the file's cache tags.
+          'tags' => $file->getCacheTags(),
           'contexts' => $cache_contexts,
         ),
       );
+      // If we're using an image style, and the current image toolkit supports
+      // this file type, apply the image style's cache tags to the rendered
+      // item.
+      if (isset($image_style) && $this->imageFactory->get($file->getFileUri())->isValid()) {
+        $elements[$delta]['#image_style'] = $image_style->id();
+        $elements[$delta]['#cache']['tags'] = Cache::mergeTags($elements[$delta]['#cache']['tags'], $image_style->getCacheTags());
+      }
     }
 
     return $elements;
diff --git a/core/modules/image/tests/src/Kernel/ImageFormatterTest.php b/core/modules/image/tests/src/Kernel/ImageFormatterTest.php
index d1b132e..ebb856b 100644
--- a/core/modules/image/tests/src/Kernel/ImageFormatterTest.php
+++ b/core/modules/image/tests/src/Kernel/ImageFormatterTest.php
@@ -4,9 +4,12 @@
 
 use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\Render\Element;
 use Drupal\entity_test\Entity\EntityTest;
 use Drupal\field\Entity\FieldConfig;
 use Drupal\field\Entity\FieldStorageConfig;
+use Drupal\file\Entity\File;
+use Drupal\image\Entity\ImageStyle;
 use Drupal\Tests\field\Kernel\FieldKernelTestBase;
 
 /**
@@ -84,7 +87,7 @@ protected function setUp() {
   /**
    * Tests the cache tags from image formatters.
    */
-  function testImageFormatterCacheTags() {
+  public function testImageFormatterCacheTags() {
     // Create a test entity with the image field set.
     $entity = EntityTest::create([
       'name' => $this->randomMachineName(),
@@ -99,4 +102,69 @@ function testImageFormatterCacheTags() {
     $this->assertEquals($entity->{$this->fieldName}[1]->entity->getCacheTags(), $build[$this->fieldName][1]['#cache']['tags'], 'Second image cache tags is as expected');
   }
 
+  /**
+   * Tests ImageFormatter's handling of SVG images.
+   *
+   * @requires extension gd
+   */
+  public function testImageFormatterSvg() {
+    // Install the default image styles.
+    $this->installConfig(['image']);
+
+    $png = File::create([
+      'uri' => 'temporary://' . $this->randomMachineName() . '.png',
+    ]);
+    $png->save();
+
+    // We need to create an actual empty PNG, or the GD toolkit will not
+    // consider the image valid.
+    $png_resource = imagecreate(100, 100);
+    imagefill($png_resource, 0, 0, imagecolorallocate($png_resource, 0, 0, 0));
+    imagepng($png_resource, $png->getFileUri());
+
+    $svg = File::create([
+      'uri' => 'temporary://' . $this->randomMachineName() . '.svg',
+    ]);
+    $svg->save();
+    // We don't have to put any real SVG data in here, because the GD toolkit
+    // won't be able to load it anyway.
+    touch($svg->getFileUri());
+
+    $entity = EntityTest::create([
+      'name' => $this->randomMachineName(),
+      $this->fieldName => [$png, $svg],
+    ]);
+    $entity->save();
+
+    // Ensure that the display is using the medium image style.
+    $component = $this->display->getComponent($this->fieldName);
+    $component['settings']['image_style'] = 'medium';
+    $this->display->setComponent($this->fieldName, $component)->save();
+
+    $build = $this->display->build($entity);
+
+    // The first image is a PNG, so it is supported by the GD image toolkit.
+    // Which means that the image style should be applied, cache tags and all.
+    $this->assertEquals('medium', $build[$this->fieldName][0]['#image_style']);
+    $this->assertCacheTags($build[$this->fieldName][0], ImageStyle::load('medium')->getCacheTags());
+
+    // The second image is an SVG, which is not supported by the GD toolkit.
+    // So it should NOT have the image style (or its cache tags) applied.
+    $this->assertArrayNotHasKey('#image_style', $build[$this->fieldName][1]);
+    $this->assertSame($svg->getCacheTags(), $build[$this->fieldName][1]['#cache']['tags']);
+  }
+
+  /**
+   * Asserts that a renderable array has a set of cache tags.
+   *
+   * @param array $renderable
+   *   The renderable array. Must have a #cache[tags] element.
+   * @param array $cache_tags
+   *   The expected cache tags.
+   */
+  protected function assertCacheTags(array $renderable, array $cache_tags) {
+    $diff = array_diff($cache_tags, $renderable['#cache']['tags']);
+    $this->assertEmpty($diff);
+  }
+
 }
