diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php
index a515fe4..3d99b21 100644
--- a/core/lib/Drupal/Core/Image/Image.php
+++ b/core/lib/Drupal/Core/Image/Image.php
@@ -101,6 +101,14 @@ public function __construct($source, ImageToolkitInterface $toolkit) {
    */
   public function getExtension() {
     $this->processInfo();
+
+    // Extension may still be empty after calling processInfo(). This happens if
+    // the image doesn't exists yet on disk, but only in memory as image
+    // resource. Try to extact the extension from the image source path.
+    if (empty($this->extension)) {
+      $this->extension = pathinfo($this->getSource(), PATHINFO_EXTENSION);
+    }
+
     return $this->extension;
   }
 
@@ -139,6 +147,14 @@ public function setWidth($width) {
   /**
    * {@inheritdoc}
    */
+  public function setExtension($extension) {
+    $this->extension = $extension;
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
   public function getFileSize() {
     $this->processInfo();
     return $this->fileSize;
diff --git a/core/lib/Drupal/Core/Image/ImageInterface.php b/core/lib/Drupal/Core/Image/ImageInterface.php
index b83c578..fde32f5 100644
--- a/core/lib/Drupal/Core/Image/ImageInterface.php
+++ b/core/lib/Drupal/Core/Image/ImageInterface.php
@@ -21,6 +21,17 @@
   public function getExtension();
 
   /**
+   * Sets the extension of the image file.
+   *
+   * @param $extension string
+   *   The extension of the file.
+   *
+   * @return self
+   *   Returns this image file.
+   */
+  public function setExtension($extension);
+
+  /**
    * Returns the height of the image file.
    *
    * @return int
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php
index 74f41ec..95b329f 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\image\Tests;
 
+use Drupal\Core\Image\Image;
 use Drupal\system\Tests\Image\ToolkitTestBase;
 
 /**
@@ -177,4 +178,23 @@ protected function assertImageEffect($effect_name, array $data) {
     return $this->assertTrue($effect->applyEffect($this->image), 'Function returned the expected value.');
   }
 
+  /**
+   * Test image save for an image created from resource.
+   */
+  public function testImageSave() {
+    $destination = 'public://' . $this->randomName() . '.png';
+
+    $res = imagecreatetruecolor(20, 20);
+
+    $image = new Image($destination, $this->container->get('image.toolkit'));
+
+    $this->assertTrue($image
+      ->setResource($res)
+      ->setWidth(20)
+      ->setHeight(20)
+      ->save());
+
+    $this->assertTrue(file_exists($destination));
+  }
+
 }
diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php
index c96f4c9..04b79fb 100644
--- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php
+++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php
@@ -68,6 +68,16 @@ public function testGetExtension() {
   }
 
   /**
+   * Tests \Drupal\Core\Image\Image::setExtension().
+   */
+  public function testSetExtension() {
+    // Make sure we've processed info once.
+    $this->image->getExtension();
+    $this->image->setExtension('jpeg');
+    $this->assertEquals($this->image->getExtension(), 'jpeg');
+  }
+
+  /**
    * Tests \Drupal\Core\Image\Image::getHeight().
    */
   public function testGetHeight() {
