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 1f6cef3..2d8544e 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php @@ -221,8 +221,17 @@ public function getInfo(ImageInterface $image) { $data = getimagesize($image->getSource()); if (isset($data) && is_array($data)) { - $extension = image_type_to_extension($data[2], FALSE); - $extension = in_array($extension, self::getAvailableExtensions()) ? $extension : ''; + // image_type_to_extension(IMAGETYPE_JPEG) always returns 'jpeg' event if + // the extension is 'jpg'. Extract the extension from the filename. + if ($data[2] == IMAGETYPE_JPEG) { + $extension = pathinfo($image->getSource(), PATHINFO_EXTENSION); + // It may be a temporary file, without extension. Fallback to 'jpg'. + $extension = in_array($extension, array('jpg', 'jpeg')) ? $extension : 'jpg'; + } + else { + $extension = image_type_to_extension($data[2], FALSE); + $extension = in_array($extension, self::getAvailableExtensions()) ? $extension : ''; + } $details = array( 'width' => $data[0], 'height' => $data[1], 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 1797b78..6917942 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php @@ -264,7 +264,7 @@ function testManipulations() { $this->assertTrue($correct_dimensions_object, format_string('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->getExtension() != 'jpg') { + if (!in_array($image->getExtension(), array('jpg', 'jpeg'))) { // Now check each of the corners to ensure color correctness. foreach ($values['corners'] as $key => $corner) { // Get the location of the corner. 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 60ef977..762288c 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 @@ -46,8 +46,17 @@ public function getInfo(ImageInterface $image) { $data = getimagesize($image->getSource()); if (isset($data) && is_array($data)) { - $extension = image_type_to_extension($data[2], FALSE); - $extension = in_array($extension, self::getAvailableExtensions()) ? $extension : ''; + // image_type_to_extension(IMAGETYPE_JPEG) always returns 'jpeg' event if + // the extension is 'jpg'. Extract the extension from the filename. + if ($data[2] == IMAGETYPE_JPEG) { + $extension = pathinfo($image->getSource(), PATHINFO_EXTENSION); + // It may be a temporary file, without extension. Fallback to 'jpg'. + $extension = in_array($extension, array('jpg', 'jpeg')) ? $extension : 'jpg'; + } + else { + $extension = image_type_to_extension($data[2], FALSE); + $extension = in_array($extension, self::getAvailableExtensions()) ? $extension : ''; + } $details = array( 'width' => $data[0], 'height' => $data[1],