Commit 2d292cd1 authored by alexpott's avatar alexpott

Issue #2477381 by mondrake: GDToolkit::getSupportedExtensions returns incomplete list

parent 11904f8e
......@@ -393,7 +393,15 @@ public static function isAvailable() {
public static function getSupportedExtensions() {
$extensions = array();
foreach (static::supportedTypes() as $image_type) {
$extensions[] = Unicode::strtolower(image_type_to_extension($image_type, FALSE));
// @todo Automatically fetch possible extensions for each mime type.
// @see https://www.drupal.org/node/2311679
$extension = Unicode::strtolower(image_type_to_extension($image_type, FALSE));
$extensions[] = $extension;
// Add some known similar extensions.
if ($extension === 'jpeg') {
$extensions[] = 'jpg';
$extensions[] = 'jpe';
}
}
return $extensions;
}
......@@ -413,6 +421,9 @@ public static function getSupportedExtensions() {
* @see image_type_to_extension()
*/
public function extensionToImageType($extension) {
if (in_array($extension, ['jpe', 'jpg'])) {
$extension = 'jpeg';
}
foreach ($this->supportedTypes() as $type) {
if (image_type_to_extension($type, FALSE) === $extension) {
return $type;
......
......@@ -107,6 +107,26 @@ function testManipulations() {
// Test that the image factory is set to use the GD toolkit.
$this->assertEqual($this->imageFactory->getToolkitId(), 'gd', 'The image factory is set to use the \'gd\' image toolkit.');
// Test the list of supported extensions.
$expected_extensions = ['png', 'gif', 'jpeg', 'jpg', 'jpe'];
$supported_extensions = $this->imageFactory->getSupportedExtensions();
$this->assertEqual($expected_extensions, array_intersect($expected_extensions, $supported_extensions));
// Test that the supported extensions map to correct internal GD image
// types.
$expected_image_types = [
'png' => IMAGETYPE_PNG,
'gif' => IMAGETYPE_GIF,
'jpeg' => IMAGETYPE_JPEG,
'jpg' => IMAGETYPE_JPEG,
'jpe' => IMAGETYPE_JPEG
];
$image = $this->imageFactory->get();
foreach ($expected_image_types as $extension => $expected_image_type) {
$image_type = $image->getToolkit()->extensionToImageType($extension);
$this->assertSame($expected_image_type, $image_type);
}
// Typically the corner colors will be unchanged. These colors are in the
// order of top-left, top-right, bottom-right, bottom-left.
$default_corners = array($this->red, $this->green, $this->blue, $this->transparent);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment