diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
index 2d5e1678ac..a772913e9f 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
@@ -248,8 +248,8 @@ public function save($destination) {
       $success = $function($this->getResource(), $destination, $this->configFactory->get('system.image.gd')->get('jpeg_quality'));
     }
     else {
-      // Always save PNG images with full transparency.
-      if ($this->getType() == IMAGETYPE_PNG) {
+      // Image types that support alpha need to be saved accordingly.
+      if (in_array($this->getType(), [IMAGETYPE_PNG, IMAGETYPE_WEBP], TRUE)) {
         imagealphablending($this->getResource(), FALSE);
         imagesavealpha($this->getResource(), TRUE);
       }
@@ -459,7 +459,7 @@ public function extensionToImageType($extension) {
    *   IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG, IMAGETYPE_PNG, etc.).
    */
   protected static function supportedTypes() {
-    return [IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF];
+    return [IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_WEBP];
   }
 
 }
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php
index fef47e9017..0c3559ed2b 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php
@@ -93,6 +93,7 @@ protected function execute(array $arguments) {
     // Fill the resource with transparency as possible.
     switch ($type) {
       case IMAGETYPE_PNG:
+      case IMAGETYPE_WEBP:
         imagealphablending($res, FALSE);
         $transparency = imagecolorallocatealpha($res, 0, 0, 0, 127);
         imagefill($res, 0, 0, $transparency);
diff --git a/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php b/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php
index cbc62397b5..b597627141 100644
--- a/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php
@@ -109,7 +109,7 @@ public function testManipulations() {
     $this->assertEqual($this->imageFactory->getToolkitId(), 'gd', 'The image factory is set to use the \'gd\' image toolkit.');
 
     // Test the list of supported extensions.
-    $expected_extensions = ['png', 'gif', 'jpeg', 'jpg', 'jpe'];
+    $expected_extensions = ['png', 'gif', 'jpeg', 'jpg', 'jpe', 'webp'];
     $supported_extensions = $this->imageFactory->getSupportedExtensions();
     $this->assertEqual($expected_extensions, array_intersect($expected_extensions, $supported_extensions));
 
@@ -121,6 +121,7 @@ public function testManipulations() {
       'jpeg' => IMAGETYPE_JPEG,
       'jpg' => IMAGETYPE_JPEG,
       'jpe' => IMAGETYPE_JPEG,
+      'webp' => IMAGETYPE_WEBP,
     ];
     $image = $this->imageFactory->get();
     foreach ($expected_image_types as $extension => $expected_image_type) {
@@ -138,6 +139,7 @@ public function testManipulations() {
       'image-test.gif',
       'image-test-no-transparency.gif',
       'image-test.jpg',
+      'img-test.webp',
     ];
 
     // Setup a list of tests to perform on each type.
@@ -212,6 +214,13 @@ public function testManipulations() {
         'arguments' => ['extension' => 'png'],
         'corners' => $default_corners,
       ],
+      'convert_webp' => [
+        'function' => 'convert',
+        'width' => 40,
+        'height' => 20,
+        'arguments' => ['extension' => 'webp'],
+        'corners' => $default_corners,
+      ],
     ];
 
     // Systems using non-bundled GD2 don't have imagerotate. Test if available.
@@ -387,7 +396,7 @@ public function testManipulations() {
     }
 
     // Test creation of image from scratch, and saving to storage.
-    foreach ([IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG] as $type) {
+    foreach ([IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_WEBP] as $type) {
       $image = $this->imageFactory->get();
       $image->createNew(50, 20, image_type_to_extension($type, FALSE), '#ffff00');
       $file = 'from_null' . image_type_to_extension($type);
diff --git a/core/tests/fixtures/files/img-test.webp b/core/tests/fixtures/files/img-test.webp
new file mode 100644
index 0000000000000000000000000000000000000000..5ce8b65757af4dd84971b214ef8445334295741a
GIT binary patch
literal 114
zcmV-&0FD1rNk&F$00012MM6+kP&iCo0000lC%^;{FCY*|+8=t2`4<or`9IqH2OwL@
z21acpIokM-1a=s#hQcg?#GlKBehq+#{;O@<hM{+-oFO7D!whED;QoTmr|Ie2S{Y+f
U&hcp?qLp)hnsh=xg-{d#0B1cfcK`qY

literal 0
HcmV?d00001