Skip to content

Commit

Permalink
fix gd driver convert to avif using format() function
Browse files Browse the repository at this point in the history
  • Loading branch information
ariaieboy committed Dec 18, 2023
1 parent 4f84e86 commit 24c15a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Drivers/Gd/GdDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,9 @@ public function format(string $format): static
case 'webp':
imagewebp($this->image, null);
break;
case 'avif':
imageavif($this->image,null);
break;
default:
throw UnsupportedImageFormat::make($format);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/ImageFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
expect($targetFile)->toHaveMime("image/$format");
})->with('drivers', ['jpeg', 'gif', 'png', 'webp', 'avif']);


it('can change to supported formats', function (ImageDriver $driver, string $format) {
if ($format === 'avif' && ! function_exists('imageavif')) {
$this->markTestSkipped('avif is not supported on this system');

return;
}

$targetFile = $this->tempDir->path("{$driver->driverName()}/format-test.$format");

$driver->loadFile(getTestJpg())->format($format)->save($targetFile);

expect($targetFile)->toHaveMime("image/$format");
})->with('drivers', ['jpeg', 'gif', 'png', 'webp', 'avif']);

it('can save tiff', function () {
$format = 'tiff';
$driver = Image::useImageDriver('imagick');
Expand Down

0 comments on commit 24c15a1

Please sign in to comment.