diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php index f7a5cd77158..ba1c03adcb6 100644 --- a/core/lib/Drupal/Core/Image/Image.php +++ b/core/lib/Drupal/Core/Image/Image.php @@ -47,13 +47,6 @@ class Image implements ImageInterface { */ protected $width = 0; - /** - * Commonly used file extension for the image. - * - * @var string - */ - protected $extension = ''; - /** * Image type represented by a PHP IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG). * @@ -61,13 +54,6 @@ class Image implements ImageInterface { */ protected $type; - /** - * MIME type (e.g. 'image/jpeg', 'image/gif', 'image/png'). - * - * @var string - */ - protected $mimeType = ''; - /** * File size in bytes. * @@ -110,14 +96,6 @@ class Image implements ImageInterface { return $this->processed; } - /** - * {@inheritdoc} - */ - public function getExtension() { - $this->processInfo(); - return $this->extension; - } - /** * {@inheritdoc} */ @@ -171,7 +149,7 @@ class Image implements ImageInterface { */ public function getMimeType() { $this->processInfo(); - return $this->mimeType; + return $this->type ? image_type_to_mime_type($this->type) : ''; } /** @@ -250,15 +228,7 @@ class Image implements ImageInterface { $this->height = $details['height']; $this->width = $details['width']; $this->type = $details['type']; - $this->mimeType = $details['mime_type']; $this->fileSize = filesize($destination); - $this->extension = pathinfo($destination, PATHINFO_EXTENSION); - - // It may be a temporary file, without extension, or an image created from - // an image resource. Fallback to default extension for this image type. - if (empty($this->extension)) { - $this->extension = image_type_to_extension($this->type, FALSE); - } $this->processed = TRUE; } diff --git a/core/lib/Drupal/Core/Image/ImageInterface.php b/core/lib/Drupal/Core/Image/ImageInterface.php index b6edda04b97..5bbe8cf504e 100644 --- a/core/lib/Drupal/Core/Image/ImageInterface.php +++ b/core/lib/Drupal/Core/Image/ImageInterface.php @@ -28,14 +28,6 @@ interface ImageInterface { */ public function isExisting(); - /** - * Returns the extension of the image file. - * - * @return string - * The extension of the file, or an empty string if the file is invalid. - */ - public function getExtension(); - /** * Returns the height of the image file. * @@ -93,7 +85,8 @@ interface ImageInterface { * Returns the MIME type of the image file. * * @return string - * The MIME type of the file, or an empty string if the file is invalid. + * The MIME type of the image file, or an empty string if the image is + * invalid. */ public function getMimeType(); diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php index 61c6ece379a..dfa8b90daf4 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php @@ -199,7 +199,6 @@ interface ImageToolkitInterface extends PluginInspectionInterface { * - "width": Width, in pixels. * - "height": Height, in pixels. * - "type": Image type represented as an IMAGETYPE_* constant. - * - "mime_type": MIME type (e.g. 'image/jpeg', 'image/gif', 'image/png'). * * @see \Drupal\Core\Image\ImageInterface::processInfo() */ diff --git a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldWidget/ImageWidget.php index 811ed0f4288..26d4deaf305 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldWidget/ImageWidget.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldWidget/ImageWidget.php @@ -166,7 +166,7 @@ class ImageWidget extends FileWidget { } else { $image = \Drupal::service('image.factory')->get($file->getFileUri()); - if ($image->getExtension()) { + if ($image->isExisting()) { $variables['width'] = $image->getWidth(); $variables['height'] = $image->getHeight(); } diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php index 1bd1d36575f..98e557270c4 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php @@ -309,7 +309,6 @@ class GDToolkit extends ImageToolkitBase { 'width' => $data[0], 'height' => $data[1], 'type' => $data[2], - 'mime_type' => $data['mime'], ); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php index d683b70d7a3..d2be8cd4a50 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php @@ -253,7 +253,7 @@ class ToolkitGdTest extends DrupalUnitTestBase { $directory = $this->public_files_directory .'/imagetest'; file_prepare_directory($directory, FILE_CREATE_DIRECTORY); - $image->save($directory . '/' . $op . '.' . $image->getExtension()); + $image->save($directory . '/' . $op . image_type_to_extension($image->getType())); $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))); diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php index d85d813e57d..862129d4935 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php @@ -59,7 +59,6 @@ class TestToolkit extends ImageToolkitBase { 'width' => $data[0], 'height' => $data[1], 'type' => $data[2], - 'mime_type' => $data['mime'], ); } diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php index d2c5fd7f6bc..6ddc2770f70 100644 --- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php @@ -77,13 +77,6 @@ class ImageTest extends UnitTestCase { ->getMock(); } - /** - * Tests \Drupal\Core\Image\Image::getExtension(). - */ - public function testGetExtension() { - $this->assertEquals($this->image->getExtension(), 'png'); - } - /** * Tests \Drupal\Core\Image\Image::getHeight(). */