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 322b0bb..6e1a572 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php @@ -10,7 +10,6 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; use Drupal\Component\Plugin\PluginBase; -use Drupal\Component\Utility\Unicode; use Drupal\system\Annotation\ImageToolkit; use Drupal\system\Plugin\ImageToolkitInterface; @@ -222,18 +221,14 @@ public function getInfo(ImageInterface $image) { $data = getimagesize($image->getSource()); if (isset($data) && is_array($data)) { - // image_type_to_extension(IMAGETYPE_JPEG) always returns 'jpeg' even 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 = Unicode::strtolower($extension); - $extension = in_array($extension, array('jpg', 'jpeg')) ? $extension : 'jpg'; - } - else { - $extension = image_type_to_extension($data[2], FALSE); - $extension = in_array($extension, static::getAvailableExtensions()) ? $extension : ''; + $extension = image_type_to_extension($data[2], FALSE); + // image_type_to_extension(IMAGETYPE_JPEG) returns 'jpeg' while we want to + // return 'jpg' (for reasons of backwards compatibility). + if ($extension === 'jpeg') { + $extension = 'jpg'; } + // Check if this image format is supported. + $extension = in_array($extension, static::getAvailableExtensions()) ? $extension : ''; $details = array( 'width' => $data[0], 'height' => $data[1], diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php index a1ddbd0..e582d23 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitInterface.php @@ -182,7 +182,7 @@ function getInfo(ImageInterface $image); public static function isAvailable(); /** - * Returns a list of image extensions handled by the image toolkit. + * Returns a list of lower case image extensions supported by the toolkit. * * @return array * An array of available image extensions. 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 648b2f6..589c843 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 (!in_array($image->getExtension(), array('jpg', 'jpeg'))) { + if ($image->getExtension() != 'jpg') { // Now check each of the corners to ensure color correctness. foreach ($values['corners'] as $key => $corner) { // Get the location of the corner. @@ -317,7 +317,7 @@ public function testExtensions() { foreach ($files as $extension => $file) { $image = $image_factory->get($file); - $expected = $extension ?: 'jpg'; + $expected = in_array($extension, array('jpeg', '')) ? 'jpg' : $extension; $this->assertEqual($image->getExtension(), $expected); } } 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 f5b336e..57c4abb 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 @@ -10,7 +10,6 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; use Drupal\Component\Plugin\PluginBase; -use Drupal\Component\Utility\Unicode; use Drupal\system\Annotation\ImageToolkit; use Drupal\system\Plugin\ImageToolkitInterface; @@ -47,18 +46,14 @@ public function getInfo(ImageInterface $image) { $data = getimagesize($image->getSource()); if (isset($data) && is_array($data)) { - // image_type_to_extension(IMAGETYPE_JPEG) always returns 'jpeg' even 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 = Unicode::strtolower($extension); - $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 : ''; + $extension = image_type_to_extension($data[2], FALSE); + // image_type_to_extension(IMAGETYPE_JPEG) returns 'jpeg' while we want to + // return 'jpg' (for reasons of backwards compatibility). + if ($extension === 'jpeg') { + $extension = 'jpg'; } + // Check if this image format is supported. + $extension = in_array($extension, static::getAvailableExtensions()) ? $extension : ''; $details = array( 'width' => $data[0], 'height' => $data[1],