diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php index f7a5cd7..6b56ccc 100644 --- a/core/lib/Drupal/Core/Image/Image.php +++ b/core/lib/Drupal/Core/Image/Image.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Image; +use Drupal\Component\Utility\Unicode; use Drupal\Core\ImageToolkit\ImageToolkitInterface; /** @@ -48,13 +49,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). * * @var int @@ -62,13 +56,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. * * @var int @@ -113,9 +100,9 @@ public function isExisting() { /** * {@inheritdoc} */ - public function getExtension() { + public function getDefaultExtension() { $this->processInfo(); - return $this->extension; + return Unicode::strtolower(image_type_to_extension($this->type, FALSE)); } /** @@ -171,7 +158,7 @@ public function getType() { */ public function getMimeType() { $this->processInfo(); - return $this->mimeType; + return image_type_to_mime_type($this->type); } /** @@ -250,15 +237,7 @@ protected function processInfo() { $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 151bef1..59f3be8 100644 --- a/core/lib/Drupal/Core/Image/ImageInterface.php +++ b/core/lib/Drupal/Core/Image/ImageInterface.php @@ -29,12 +29,12 @@ public function isSupported(); public function isExisting(); /** - * Returns the extension of the image file. + * Returns the default file extension of the image, based on its type. * * @return string - * The extension of the file, or an empty string if the file is invalid. + * The default file extension of the image. */ - public function getExtension(); + public function getDefaultExtension(); /** * Returns the height of the image file. @@ -93,7 +93,7 @@ public function getType(); * 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. */ public function getMimeType(); diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php index 61c6ece..dfa8b90 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php @@ -199,7 +199,6 @@ public function scaleAndCrop(ImageInterface $image, $width, $height); * - "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 94528ae..cbb5c54 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 @@ -160,7 +160,7 @@ public static function process($element, &$form_state, $form) { } 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 1bd1d36..98e5572 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 @@ public function getInfo(ImageInterface $image) { '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 d683b70..72ea5ad 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 @@ function testManipulations() { $directory = $this->public_files_directory .'/imagetest'; file_prepare_directory($directory, FILE_CREATE_DIRECTORY); - $image->save($directory . '/' . $op . '.' . $image->getExtension()); + $image->save($directory . '/' . $op . '.' . $image->getDefaultExtension()); $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 d85d813..862129d 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 @@ public function getInfo(ImageInterface $image) { '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 d2c5fd7..ca1576a 100644 --- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php @@ -78,10 +78,10 @@ protected function getToolkitMock(array $stubs = array()) { } /** - * Tests \Drupal\Core\Image\Image::getExtension(). + * Tests \Drupal\Core\Image\Image::getDefaultExtension(). */ public function testGetExtension() { - $this->assertEquals($this->image->getExtension(), 'png'); + $this->assertEquals($this->image->getDefaultExtension(), 'png'); } /**