diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
index 98ae863..00e2885 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
@@ -30,11 +30,11 @@ class GDToolkit extends ImageToolkitBase {
   protected $resource = NULL;
 
   /**
-   * Image type represented by a PHP IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG).
+   * The image extension.
    *
-   * @var int
+   * @var string
    */
-  protected $type;
+  protected $extension;
 
   /**
    * Image information from a file, available prior to loading the GD resource.
@@ -128,8 +128,18 @@ protected function load() {
     if (!$this->isValid()) {
       return FALSE;
     }
+    $function = '';
+    switch ($this->getExtension()) {
+      case 'jpeg':
+      case 'jpg':
+      case 'jpe':
+        $function = 'imagecreatefromjpeg';
+        break;
 
-    $function = 'imagecreatefrom' . image_type_to_extension($this->getType(), FALSE);
+      default:
+        $function = 'imagecreatefrom' . $this->getExtension();
+
+    }
     if (function_exists($function) && $resource = $function($this->getImage()->getSource())) {
       $this->setResource($resource);
       if (imageistruecolor($resource)) {
@@ -138,7 +148,7 @@ protected function load() {
       else {
         // Convert indexed images to true color, so that filters work
         // correctly and don't result in unnecessary dither.
-        $new_image = $this->createTmp($this->getType(), imagesx($resource), imagesy($resource));
+        $new_image = $this->createTmp($this->getMimeType(), imagesx($resource), imagesy($resource));
         if ($ret = (bool) $new_image) {
           imagecopy($new_image, $resource, 0, 0, 0, 0, imagesx($resource), imagesy($resource));
           imagedestroy($resource);
@@ -174,16 +184,28 @@ public function save($destination) {
       $destination = drupal_realpath($destination);
     }
 
-    $function = 'image' . image_type_to_extension($this->getType(), FALSE);
+
+    $function = '';
+    switch ($this->getExtension()) {
+      case 'jpeg':
+      case 'jpg':
+      case 'jpe':
+        $function = 'imagejpeg';
+        break;
+
+      default:
+        $function = 'image' . $this->getExtension();
+
+    }
     if (!function_exists($function)) {
       return FALSE;
     }
-    if ($this->getType() == IMAGETYPE_JPEG) {
+    if ($this->getMimeType() == 'image/jpeg') {
       $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) {
+      if ($this->getMimeType() == 'image/png') {
         imagealphablending($this->getResource(), FALSE);
         imagesavealpha($this->getResource(), TRUE);
       }
@@ -200,21 +222,31 @@ public function save($destination) {
    * {@inheritdoc}
    */
   public function parseFile() {
+    $extension = Unicode::strtolower(pathinfo($this->getImage()->getSource(), PATHINFO_EXTENSION));
+    $this->setExtension($extension);
     $data = @getimagesize($this->getImage()->getSource());
-    if ($data && in_array($data[2], static::supportedTypes())) {
-      $this->setType($data[2]);
+    if ($data) {
       $this->preLoadInfo = $data;
       return TRUE;
     }
+    elseif (!$data && $extension == 'webp') {
+      // The getimagesize function does not support WebP, load the resource so
+      // that isValid() still returns TRUE if it is in fact a valid image.
+      $this->preLoadInfo = TRUE;
+      if (!$this->load()) {
+        $this->preLoadInfo = FALSE;
+        return FALSE;
+      }
+      return TRUE;
+    }
     return FALSE;
   }
 
   /**
    * Creates a truecolor image preserving transparency from a provided image.
    *
-   * @param int $type
-   *   An image type represented by a PHP IMAGETYPE_* constant (e.g.
-   *   IMAGETYPE_JPEG, IMAGETYPE_PNG, etc.).
+   * @param string $mime_type
+   *   An image MIME type (e.g. 'image/jpeg', 'image/png', etc.).
    * @param int $width
    *   The new width of the new image, in pixels.
    * @param int $height
@@ -223,10 +255,10 @@ public function parseFile() {
    * @return resource
    *   A GD image handle.
    */
-  public function createTmp($type, $width, $height) {
+  public function createTmp($mime_type, $width, $height) {
     $res = imagecreatetruecolor($width, $height);
 
-    if ($type == IMAGETYPE_GIF) {
+    if ($mime_type == 'image/gif') {
       // Find out if a transparent color is set, will return -1 if no
       // transparent color has been defined in the image.
       $transparent = imagecolortransparent($this->getResource());
@@ -250,7 +282,7 @@ public function createTmp($type, $width, $height) {
         }
       }
     }
-    elseif ($type == IMAGETYPE_PNG) {
+    elseif ($mime_type == 'image/png') {
       imagealphablending($res, FALSE);
       $transparency = imagecolorallocatealpha($res, 0, 0, 0, 127);
       imagefill($res, 0, 0, $transparency);
@@ -295,37 +327,48 @@ public function getHeight() {
   }
 
   /**
-   * Gets the PHP type of the image.
+   * Gets the MIME type guesser.
    *
-   * @return int
-   *   The image type represented by a PHP IMAGETYPE_* constant (e.g.
-   *   IMAGETYPE_JPEG).
+   * @return \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface
+   *   The MIME type guesser.
    */
-  public function getType() {
-    return $this->type;
+  public function getMimeTypeGuesser() {
+    return \Drupal::service('file.mime_type.guesser.extension');
   }
 
   /**
-   * Sets the PHP type of the image.
+   * Gets the extension of the image.
    *
-   * @param int $type
-   *   The image type represented by a PHP IMAGETYPE_* constant (e.g.
-   *   IMAGETYPE_JPEG).
+   * @return string
+   *   The extension.
+   */
+  public function getExtension() {
+    return $this->extension;
+  }
+
+  /**
+   * Sets the extension of the image.
+   *
+   * @param string $extension
+   *   The image extension without the leading dot.
    *
    * @return $this
    */
-  public function setType($type) {
-    if (in_array($type, static::supportedTypes())) {
-      $this->type = $type;
+  public function setExtension($extension) {
+    $extension = Unicode::strtolower($extension);
+    if (in_array($extension, static::getSupportedExtensions())) {
+      $this->extension = $extension;
     }
     return $this;
   }
 
+
   /**
    * {@inheritdoc}
    */
   public function getMimeType() {
-    return $this->getType() ? image_type_to_mime_type($this->getType()) : '';
+    // The current extension might differ from the original files extension.
+    return $this->getMimeTypeGuesser()->guess(pathinfo($this->getImage()->getSource(), PATHINFO_FILENAME) . '.' . $this->getExtension());
   }
 
   /**
@@ -361,21 +404,17 @@ public static function isAvailable() {
    * {@inheritdoc}
    */
   public static function getSupportedExtensions() {
-    $extensions = array();
-    foreach (static::supportedTypes() as $image_type) {
-      $extensions[] = Unicode::strtolower(image_type_to_extension($image_type, FALSE));
-    }
-    return $extensions;
+    // All extensions that have an imagecreatefrom* and image* function in PHP.
+    return array(
+      'jpeg',
+      'jpg',
+      'jpe',
+      'png',
+      'wbmp',
+      'webp',
+      'gif',
+      'xbm',
+    );
   }
 
-  /**
-   * Returns a list of image types supported by the toolkit.
-   *
-   * @return array
-   *   An array of available image types. An image type is represented by a PHP
-   *   IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG, IMAGETYPE_PNG, etc.).
-   */
-  protected static function supportedTypes() {
-    return array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
-  }
 }
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php
index 95d8fd7..7c38e83 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php
@@ -80,7 +80,7 @@ protected function validateArguments(array $arguments) {
    * {@inheritdoc}
    */
   protected function execute(array $arguments) {
-    $res = $this->getToolkit()->createTmp($this->getToolkit()->getType(), $arguments['width'], $arguments['height']);
+    $res = $this->getToolkit()->createTmp($this->getToolkit()->getMimeType(), $arguments['width'], $arguments['height']);
 
     if (!imagecopyresampled($res, $this->getToolkit()->getResource(), 0, 0, $arguments['x'], $arguments['y'], $arguments['width'], $arguments['height'], $arguments['width'], $arguments['height'])) {
       return FALSE;
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php
index bc192c7..06788c0 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php
@@ -59,7 +59,7 @@ protected function validateArguments(array $arguments) {
    * {@inheritdoc}
    */
   protected function execute(array $arguments = array()) {
-    $res = $this->getToolkit()->createTmp($this->getToolkit()->getType(), $arguments['width'], $arguments['height']);
+    $res = $this->getToolkit()->createTmp($this->getToolkit()->getMimeType(), $arguments['width'], $arguments['height']);
 
     if (!imagecopyresampled($res, $this->getToolkit()->getResource(), 0, 0, 0, 0, $arguments['width'], $arguments['height'], $this->getToolkit()->getWidth(), $this->getToolkit()->getHeight())) {
       return FALSE;
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
index 0284b42..a061b58 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
@@ -59,7 +59,7 @@ protected function validateArguments(array $arguments) {
     // Store the color index for the background as that is what GD uses.
     $arguments['background_idx'] = imagecolorallocatealpha($this->getToolkit()->getResource(), $background['red'], $background['green'], $background['blue'], $background['alpha']);
 
-    if ($this->getToolkit()->getType() === IMAGETYPE_GIF) {
+    if ($this->getToolkit()->getMimeType() === 'image/gif') {
       // GIF does not work with a transparency channel, but can define 1 color
       // in its palette to act as transparent.
 
diff --git a/core/modules/system/src/Tests/Image/ToolkitGdTest.php b/core/modules/system/src/Tests/Image/ToolkitGdTest.php
index c3f8e1c..9b93f15 100644
--- a/core/modules/system/src/Tests/Image/ToolkitGdTest.php
+++ b/core/modules/system/src/Tests/Image/ToolkitGdTest.php
@@ -245,7 +245,7 @@ function testManipulations() {
         $image_truecolor = imageistruecolor($toolkit->getResource());
         $this->assertTrue($image_truecolor, String::format('Image %file after load is a truecolor image.', array('%file' => $file)));
 
-        if ($image->getToolkit()->getType() == IMAGETYPE_GIF) {
+        if ($image->getToolkit()->getMimeType() == 'image/gif') {
           if ($op == 'desaturate') {
             // Transparent GIFs and the imagefilter function don't work together.
             $values['corners'][3][3] = 0;
@@ -285,14 +285,14 @@ function testManipulations() {
 
         $directory = $this->public_files_directory .'/imagetest';
         file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
-        $file_path = $directory . '/' . $op . image_type_to_extension($image->getToolkit()->getType());
+        $file_path = $directory . '/' . $op . '.' . $image->getToolkit()->getExtension();
         $image->save($file_path);
 
         $this->assertTrue($correct_dimensions_real, String::format('Image %file after %action action has proper dimensions.', array('%file' => $file, '%action' => $op)));
         $this->assertTrue($correct_dimensions_object, String::format('Image %file object after %action action is reporting the proper height and width values.', array('%file' => $file, '%action' => $op)));
 
         // JPEG colors will always be messed up due to compression.
-        if ($image->getToolkit()->getType() != IMAGETYPE_JPEG) {
+        if ($image->getToolkit()->getMimeType() != 'image/jpeg') {
           // Now check each of the corners to ensure color correctness.
           foreach ($values['corners'] as $key => $corner) {
             // The test gif that does not have transparency has yellow where the
diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php
index fa91f28..6933bf6 100644
--- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php
+++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php
@@ -170,11 +170,11 @@ public function testGetFileSize() {
   }
 
   /**
-   * Tests \Drupal\Core\Image\Image::getToolkit()->getType().
+   * Tests \Drupal\Core\Image\Image::getToolkit()->getMimeType().
    */
-  public function testGetType() {
+  public function testToolkitGetMimeType() {
     $this->getTestImage(FALSE);
-    $this->assertEquals(IMAGETYPE_PNG, $this->image->getToolkit()->getType());
+    $this->assertEquals('image/png', $this->image->getToolkit()->getMimeType());
   }
 
   /**
