diff --git a/system/Images/Handlers/GDHandler.php b/system/Images/Handlers/GDHandler.php index 15bb97b6b839..6620dcac431a 100644 --- a/system/Images/Handlers/GDHandler.php +++ b/system/Images/Handlers/GDHandler.php @@ -227,6 +227,7 @@ public function save(?string $target = null, int $quality = 90): bool // for png and webp we can actually preserve transparency if (in_array($this->image()->imageType, $this->supportTransparency, true)) { + imagepalettetotruecolor($this->resource); imagealphablending($this->resource, false); imagesavealpha($this->resource, true); } diff --git a/tests/_support/Images/rocket.png b/tests/_support/Images/rocket.png new file mode 100644 index 000000000000..07ca8e212637 Binary files /dev/null and b/tests/_support/Images/rocket.png differ diff --git a/tests/system/Images/GDHandlerTest.php b/tests/system/Images/GDHandlerTest.php index b605c54a5c9c..c6fce3e37290 100644 --- a/tests/system/Images/GDHandlerTest.php +++ b/tests/system/Images/GDHandlerTest.php @@ -412,6 +412,15 @@ public function testImageConvert(): void $this->assertSame(exif_imagetype($this->start . 'work/ci-logo.png'), IMAGETYPE_PNG); } + public function testImageConvertPngToWebp(): void + { + $this->handler->withFile($this->origin . 'rocket.png'); + $this->handler->convert(IMAGETYPE_WEBP); + $saved = $this->start . 'work/rocket.webp'; + $this->handler->save($saved); + $this->assertSame(exif_imagetype($saved), IMAGETYPE_WEBP); + } + public function testImageReorientLandscape(): void { for ($i = 0; $i <= 8; $i++) {