Skip to content

fix: Image::save() causes error with webp #8210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions system/Images/Handlers/GDHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Binary file added tests/_support/Images/rocket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/system/Images/GDHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down