Skip to content

Commit 6fab8e7

Browse files
authored
Merge pull request #8210 from kenjis/fix-image-imagewebp-error
fix: Image::save() causes error with webp
2 parents d980e99 + e113ff1 commit 6fab8e7

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Diff for: system/Images/Handlers/GDHandler.php

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ public function save(?string $target = null, int $quality = 90): bool
227227

228228
// for png and webp we can actually preserve transparency
229229
if (in_array($this->image()->imageType, $this->supportTransparency, true)) {
230+
imagepalettetotruecolor($this->resource);
230231
imagealphablending($this->resource, false);
231232
imagesavealpha($this->resource, true);
232233
}

Diff for: tests/_support/Images/rocket.png

55.6 KB
Loading

Diff for: tests/system/Images/GDHandlerTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ public function testImageConvert(): void
412412
$this->assertSame(exif_imagetype($this->start . 'work/ci-logo.png'), IMAGETYPE_PNG);
413413
}
414414

415+
public function testImageConvertPngToWebp(): void
416+
{
417+
$this->handler->withFile($this->origin . 'rocket.png');
418+
$this->handler->convert(IMAGETYPE_WEBP);
419+
$saved = $this->start . 'work/rocket.webp';
420+
$this->handler->save($saved);
421+
$this->assertSame(exif_imagetype($saved), IMAGETYPE_WEBP);
422+
}
423+
415424
public function testImageReorientLandscape(): void
416425
{
417426
for ($i = 0; $i <= 8; $i++) {

0 commit comments

Comments
 (0)