Skip to content
Snippets Groups Projects
Unverified Commit d829a0e5 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2340699 by mondrake, andypost, jofitz, Jelle_S, Yiannis.Tzikas.Ziogos,...

Issue #2340699 by mondrake, andypost, jofitz, Jelle_S, Yiannis.Tzikas.Ziogos, kiamlaluno, fietserwin, alexpott, Mixologic, attiks, anavarre: Let GDToolkit support WEBP image format
parent 9f7b53f0
No related branches found
No related tags found
No related merge requests found
......@@ -256,8 +256,8 @@ public function save($destination) {
$success = $function($this->getResource(), $destination, $this->configFactory->get('system.image.gd')->get('jpeg_quality'));
}
else {
// Always save PNG images with full transparency.
if ($this->getType() == IMAGETYPE_PNG) {
// Image types that support alpha need to be saved accordingly.
if (in_array($this->getType(), [IMAGETYPE_PNG, IMAGETYPE_WEBP], TRUE)) {
imagealphablending($this->getResource(), FALSE);
imagesavealpha($this->getResource(), TRUE);
}
......@@ -467,7 +467,7 @@ public function extensionToImageType($extension) {
* IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG, IMAGETYPE_PNG, etc.).
*/
protected static function supportedTypes() {
return [IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF];
return [IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_WEBP];
}
}
......@@ -93,6 +93,7 @@ protected function execute(array $arguments) {
// Fill the resource with transparency as possible.
switch ($type) {
case IMAGETYPE_PNG:
case IMAGETYPE_WEBP:
imagealphablending($res, FALSE);
$transparency = imagecolorallocatealpha($res, 0, 0, 0, 127);
imagefill($res, 0, 0, $transparency);
......
......@@ -109,7 +109,7 @@ public function testManipulations() {
$this->assertEqual('gd', $this->imageFactory->getToolkitId(), 'The image factory is set to use the \'gd\' image toolkit.');
// Test the list of supported extensions.
$expected_extensions = ['png', 'gif', 'jpeg', 'jpg', 'jpe'];
$expected_extensions = ['png', 'gif', 'jpeg', 'jpg', 'jpe', 'webp'];
$supported_extensions = $this->imageFactory->getSupportedExtensions();
$this->assertEqual($expected_extensions, array_intersect($expected_extensions, $supported_extensions));
......@@ -121,6 +121,7 @@ public function testManipulations() {
'jpeg' => IMAGETYPE_JPEG,
'jpg' => IMAGETYPE_JPEG,
'jpe' => IMAGETYPE_JPEG,
'webp' => IMAGETYPE_WEBP,
];
$image = $this->imageFactory->get();
foreach ($expected_image_types as $extension => $expected_image_type) {
......@@ -138,6 +139,7 @@ public function testManipulations() {
'image-test.gif',
'image-test-no-transparency.gif',
'image-test.jpg',
'img-test.webp',
];
// Setup a list of tests to perform on each type.
......@@ -212,6 +214,13 @@ public function testManipulations() {
'arguments' => ['extension' => 'png'],
'corners' => $default_corners,
],
'convert_webp' => [
'function' => 'convert',
'width' => 40,
'height' => 20,
'arguments' => ['extension' => 'webp'],
'corners' => $default_corners,
],
];
// Systems using non-bundled GD2 don't have imagerotate. Test if available.
......@@ -387,7 +396,7 @@ public function testManipulations() {
}
// Test creation of image from scratch, and saving to storage.
foreach ([IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG] as $type) {
foreach ([IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_WEBP] as $type) {
$image = $this->imageFactory->get();
$image->createNew(50, 20, image_type_to_extension($type, FALSE), '#ffff00');
$file = 'from_null' . image_type_to_extension($type);
......
core/tests/fixtures/files/img-test.webp

114 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment