diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php index cc62f4a..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; } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php index f00ecf1..95b329f 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php @@ -191,7 +191,6 @@ public function testImageSave() { $this->assertTrue($image ->setResource($res) ->setWidth(20) - ->setExtension('png') ->setHeight(20) ->save());